From ArchWiki
Revision as of 10:57, 20 June 2011 by (Talk | contribs) (You can also uso sudo to start & install MySQL)

Jump to: navigation, 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 the setup script as root:

# /etc/rc.d/mysqld start && mysql_secure_installation

or with sudo:

# sudo /etc/rc.d/mysqld start && sudo mysql_secure_installation

Then restart MySQL:

# /etc/rc.d/mysqld restart

To start MySQL automatically at boot, edit /etc/rc.conf and add the mysqld daemon:

DAEMONS=(... mysqld ...)


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 and started it:

# mysql_upgrade -u root -p

Running multiple instances (MySQL 4 and MySQL 5)

MySQL4: You can get the MySQL binaries from here It is best to install them into:


Copy the start-up script to:


as instructed in the README:

#cp  /usr/local/mysql/support-files/mysql.server /etc/rc.d/mysqld4

In the startup script, it helps to explicitly set


(make sure the referenced directories are created with suitable permissions)

Copy your choice of config file:

#cp /usr/local/mysql/support-files/my-medium.cnf /usr/local/mysql/data/my.cnf

In the config file, set the socket file, and tcp/ip port:

port            = 3307
socket          = /usr/local/var/run/mysql/mysql4.sock
port            = 3307
socket          = /usr/local/var/run/mysqld/mysql4.sock

MySQL5: The default start-up script in:


does not handle multiple instances of mysql.

Edit the file. Find this line:

getPID() {
  echo $(pgrep -u mysql mysqld 2>/dev/null);

And replace it with:

getPID() {
  echo $(pgrep -u mysql -f /usr/bin/mysqld 2>/dev/null);

Start up the services:

/etc/rc.d/mysqld start
/etc/rc.d/mysqld4 start

Optional, start the services automatically (in /etc/rc.conf) add:

DAEMONS=(... mysqld4 mysqld)

That should be it!


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

More Resources