MySQL

From ArchWiki

Jump to: navigation, search


i18n
English
Türkçe
Deutsch
Español
Italiano
Česky
简体中文

Contents

Introduction

MySQL is a widely spread, multi-threaded, multi-user SQL database. For more information about features, see the official homepage.

Installation

Install the mysql package:

# pacman -S mysql

After installing MySQL you should run arch's init script as root:

# /etc/rc.d/mysqld start

This will take care of the basic configuration as adding system users and creating log files. This script also prints out how to configure MySQL after the first start.

Configuration

Once you've started the MySQL server, you probably want to add a root account in order to maintain your MySQL users and databases. This can be done manually or automatically, as mentioned by the output of the above script. Either run the commands to set a password for the root account, or run the secure installation script.

You now should be able to do further configuration using your favorite interface. For example you can use MySQL's command line tool to login as root into your MySQL server:

$ mysql -p -u root

To start MySQL at bootup add mysqld to the list of daemons in /etc/rc.conf or add /etc/rc.d/mysqld start to /etc/rc.local.

Enable remote access

The MySQL server does not listen on the TCP port 3306 by default. To allow (remote) TCP connections, comment the following line in /etc/my.cnf:

skip-networking

Remember to edit /etc/hosts.allow by adding the following lines:

mysqld: ALL : ALLOW
mysqld-max: ALL : ALLOW

Upgrading

Might consider to run this command after you have upgraded MySQL:

# mysql_upgrade -u root -p

Troubleshooting

Mysql daemon can't start

If you see something like this:

 # /etc/rc.d/mysqld restart
 :: Stopping MySQL  [FAIL] 
 :: Starting MySQL  [FAIL]

and no entry in log files, you might check permission of files in directories /var/lib/mysql and /var/lib/mysql/mysql. If owner of files in this directories isn't mysql:mysql, you should do following:

 # chown mysql:mysql /var/lib/mysql -R

If you run into permission problems despite having followed the above ensure that your my.cnf is copied to /etc/:

 # cp /etc/mysql/my.cnf /etc/my.cnf

Now try and restart the daemon.

If you run mysqld and the following error appears:

 Fatal error: Can’t open and lock privilege tables: Table ‘mysql.host’ doesn’t exist

Run the following command to install the default tables:

 # mysql_install_db --user=mysql --ldata=/var/lib/mysql/

Unable to run mysql_upgrade cause MySQL can't start.

Try run MySQL in safemode:

# mysqld_safe --datadir=/var/lib/mysql/

And then run:

# mysql_upgrade -u root -p

How to Reset the Root Password

Stop mysqld daemon

# /etc/rc.d/mysqld stop
# mysqld_safe --skip-grant-tables &

Connect to mysql server

# mysql -u root mysql

Change root password:

 mysql> UPDATE user SET password=PASSWORD("NEW_PASSWORD") WHERE User='root';
 mysql> FLUSH PRIVILEGES;
 mysql> exit

Then restart daemon:

# /etc/rc.d/mysqld restart

You're done

More Resources

Personal tools