MySQL
MySQL is a widely spread, multi-threaded, multi-user SQL database. For more information about features, see the official homepage.
Contents
Installation
Install the mysql package:
# pacman -S mysql
After installing MySQL you should run the setup script as root:
# rc.d start mysqld && mysql_secure_installation
Then restart MySQL:
# rc.d restart mysqld
To start MySQL automatically at boot, edit /etc/rc.conf and add the mysqld daemon:
DAEMONS=(... mysqld ...)
If you use systemd,add this two files. Template:File
Start MySQL server:
# systemctl start mysqld.service
To start MySQL automatically at boot,
# systemctl enable mysqld.service
Configuration
Once you have 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:
skip-networking
Upgrading
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:
/usr/local/mysql
Copy the start-up script to:
/etc/rc.d
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
Basedir=/usr/local/mysql pid_file=/usr/local/var/run/mysql/mysql4.pid
(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:
[client] port = 3307 socket = /usr/local/var/run/mysql/mysql4.sock
[mysqld] port = 3307 socket = /usr/local/var/run/mysqld/mysql4.sock
MySQL5: The default start-up script in:
/etc/rc.d/mysqld
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!
Troubleshooting
Running mysqld start && mysql_secure_installation gives an error about running as root
If you see something like this:
[ERROR] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root! [ERROR] Aborting [Note] mysqld: Shutdown complete
you probably forgot to use ./ in front of the command if you are in /etc/rc.d, or you aren't using the full path.
Mysql daemon cannot 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 is not 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 ‘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 because MySQL cannot 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 mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root'; mysql> FLUSH PRIVILEGES; mysql> exit
Then restart daemon:
# /etc/rc.d/mysqld restart
You are done.
More Resources
- LAMP - Arch wiki article covering the setup of a LAMP server (Linux Apache MySQL PHP)
- http://www.mysql.com/
- Frontend aur/mysql-gui-tools community/mysql-workbench