SQL Tutorial

12 / 59
   

Managing MySQL Database

Database management is done by Database Administrators (DBAs) who:

  • Maintain the infrastructure of the database
  • Maintain the storage of the database
  • Stop and start the database
  • Backup and restore the database
  • Tune the database for optimum performance
  • Grants to and revokes permissions from other users as needed

Database developers and end users don't need to perform these tasks. We will have a brief look at a few of the DBA tasks.

Starting MySQL Server:

  • MySQL Server binary mysqld is used to start the database server.
    root access is required.
    root$ /usr/bin/safe_mysqld &
  • To get database instance started at server boot:
    Edit file /etc/rc.local and add below line in the file:
    /etc/init.d/mysqld start
  • Process mysqld is core process of MySQL Server.

Connecting to MySQL Server from CLI:

You establish the MySQL database using the MySQL binary at the command prompt.

  • -u -> MySQL userid created by DBA for the users
  • -p > Password to connect to MySQL server as given by DBA to the users
  • -h -> Hostname where MySQL Server is running. Not needed if server is running on local machine.
  • Password can also be given in same command by putting the password just after -p without any spaces.
    $ mysql -u username -p[password] -h [hostname]
    OR $ mysql -u username -p
    Enter password:**
  • To exit, type exit and Enter:
    mysql> exit

Shutting down MySQL Server:

Done using administrators tasks binary mysqladmin
root$ /usr/bin/mysqladmin -u root -p shutdown
Enter password: **