From ArchWiki
Revision as of 18:01, 29 April 2010 by Cognhuepan (talk | contribs) (Mysql daemon can't start)
Jump to navigation Jump to search

This template has only maintenance purposes. For linking to local translations please use interlanguage links, see Help:i18n#Interlanguage links.

Local languages: Català – Dansk – English – Español – Esperanto – Hrvatski – Indonesia – Italiano – Lietuviškai – Magyar – Nederlands – Norsk Bokmål – Polski – Português – Slovenský – Česky – Ελληνικά – Български – Русский – Српски – Українська – עברית – العربية – ไทย – 日本語 – 正體中文 – 简体中文 – 한국어

External languages (all articles in these languages should be moved to the external wiki): Deutsch – Français – Română – Suomi – Svenska – Tiếng Việt – Türkçe – فارسی

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


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.


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 Template:Codeline to the list of daemons in Template:Filename or add Template:Codeline to Template:Filename.

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 Template:Filename:


Remember to edit Template:Filename by adding the following lines:

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


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

# mysql_upgrade -u root -p


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 Template:Filename and Template:Filename. 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 Template:Filename is copied to /etc/:

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

Now try and restart the daemon.

If you get these messages in your Template:Filename

 [ERROR] Can't start server : Bind on unix socket: Permission denied
 [ERROR] Do you already have another mysqld server running on socket: /var/run/mysqld/mysqld.sock ?
 [ERROR] Aborting

you should change permissions of Template:Filename like so:

 # chown mysql:mysql /var/run/mysqld -R

If you run mysqld and the following error appears:

 Fatal error: Can’t open and lock privilege tables: Table ‘’ 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> exit

Then restart daemon:

# /etc/rc.d/mysqld restart

You're done

General MySQL Connectivity

Check /var/run/mysqld for mysqld.sock and /tmp for mysql.sock. If mysql.sock doesn't exist, create a softlink:

# ln -s /var/run/mysqld/mysqld.sock /tmp/mysql.sock

Then restart the daemon:

# /etc/rc.d/mysqld restart

More Resources

  • LAMP - Arch wiki article covering the setup of a LAMP server (Linux Apache MySQL PHP)
  • Frontend - community/mysql-gui-tools