Accessing a MySQL Server

MySQL is popular enough that it is distributed by default with most modern Linux distributions. Like many client-server applications, MySQL is usually distributed as multiple packages. Most often this means there are separate packages for the server binaries and the client binaries, although there may also be a third package that includes “common” code. Be sure to familiarize yourself with your distribution’s package management system so you can effectively determine what software is installed on your system. Refer to Chapter 5 for more information on the common Linux package managers.

Assuming that the MySQL server package is installed, the server is started the same way that most Linux services are started:

# /etc/rc.d/init.d/mysqld start
Starting MySQL:           [  OK  ]

You should now have a running mysqld process, listening on TCP port 3306 by default. You can verify both of these with the ps and netstat commands, respectively:

# ps aux | grep -i mysqld
root 1865 0.0 0.2 4656 1132 pts/0 S 22:20 0:00 /bin/sh \
          /usr/bin/mysqld_safe --datadir=/var/lib/mysql \
          --socket=/var/lib/mysql/mysql.sock --log-error=\
          /var/log/mysqld.log --pidfile=\
mysql 1989 0.3 3.6 161508 19012 pts/0 Sl 22:20 0:00 \
          /usr/libexec/mysqld --basedir=/usr --datadir=\
          /var/lib/mysql --user=mysql --pid-file=\
          /var/run/mysqld/ --skipexternal-locking \
# netstat -anp | grep "LISTEN" | grep "mysqld" tcp 0 0* ...

Get LPI Linux Certification in a Nutshell, 3rd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.