Christian Zartl, BSc

Private blog and WWW page

Christian Zartl, BSc

Christian Zartl, BSc - Private blog and WWW page

MySQL on Linux

I will not write another blog article about how to install MySQL on Linux here. There are so many on the Internet and depending on the Linux distribution you use, it is often very easy.

Still there are some tricky steps you have to follow after a successful installation, which I would like to share here with you:

Allow remote connections

By default, MySQL does not allow remote connections right after installation. This is a good security setting, but not really useful in normal operation. So you have to allow remote connections first.

Open my.cnf with the text editor of your choice. I always use the easiest common one, nano:

sudo nano /etc/mysql/my.cnf

Find the line bind-address = 127.0.0.1 and comment it out:

[...]
# bind-address = 127.0.0.1
[...]

127.0.0.1 is the localhost and you could also configure this for specific hosts if you like to. Now restart the MySQL service:

sudo service mysql restart
mysql start/running, process 1795

Finally you could check for the open MySQL port:

sudo netstat -tap
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State	PID/Program name
tcp        0      0 *:mysql       *:*             LISTEN   1711/mysqld

Create users and grant access

During the installation you are asked for a MySQL root password and even if it is optional, you really should set one. So you can login to your MySQL monitor:

mysql --user=root --password=*** mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 37
Server version: 5.1.41-3ubuntu12.10 (Ubuntu)

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

Now you are advised to create users so you don't have to use your root for other databases:

mysql> CREATE USER 'atcz01admin'@'%' IDENTIFIED BY '***';
Query OK, 0 rows affected (0.00 sec)

This will create the user atcz01admin with the password *** for all (%) hosts. Afterwards you have to grant this new user access to specific tables:

mysql> GRANT ALL PRIVILEGES ON *.* TO 'atcz01admin'@'%'
    -> WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)

As this is my admin account, I will allow all access rights (ALL PRIVILEGES) on all tables in all databases (*.*). I will install a database called sugarcrm on this server, so I additionally create another user who will have access to this database only:

mysql> CREATE USER 'sugarcrm'@'localhost' IDENTIFIED BY '***';
Query OK, 0 rows affected (0.00 sec)

As you can see this user won't be used for remote administration, but only for a local application running on this server. Now you can leave the MySQL monitor again:

mysql> quit
Bye

Remote administration

Even if you could do anything via the command line on MySQL, a GUI can make your life just much easier. I would really recommend you to use MySQL Workbench for this. It can be installed on Windows, Linux or Mac OS.

It allows you to store several connections to maintain multiple MySQL servers:

MySQL Workbench

You can even save your password so you can connect with only one click:

MySQL Workbench Server Instance Profile Password Vault

You can also easily restore databases from previous backups:

MySQL Workbench

Restore Database

Kategorie: Howtos

Deine E-Mail-Adresse wird nicht veröffentlicht. Pflichtfelder sind markiert *

*