MySQL is a widely spread, multi-threaded, multi-user SQL database. For more information about features, see the [http://www.mysql.com/ official homepage].

MySQL is a widely spread, multi-threaded, multi-user SQL database. For more information about features, see the [http://www.mysql.com/ official homepage].

+

+

{{Note|MariaDB is now officially our default implementation of MySQL.It is recommended for all users to upgrade to [[MariaDB]]. MySQL will be dropped from the repositories to the AUR before 2013/4/26. See [https://www.archlinux.org/news/mariadb-replaces-mysql-in-repositories/ the announcement].}}

+

+

== Upgrade to MariaDB ==

+

Users who want to switch will need to install mariadb, libmariadbclient or mariadb-clients and execute mysql_upgrade in order to migrate their systems.

+

# systemctl stop mysqld

+

# pacman -S mariadb libmariadbclient mariadb-clients

+

# systemctl start mysqld

+

# mysql_upgrade -p

+

== Installation ==

== Installation ==

−

Install the {{Pkg|mysql}} package which is available in the [[Official Repositories|official repositories]].

+

[[pacman|Install]] the {{Pkg|mysql}} package from the [[Official Repositories|official repositories]].

+

+

After installing MySQL, start the ''mysqld'' [[Daemons|daemon]].

−

After installing MySQL, start the daemon and run the setup script:

+

Run the setup script and restart the daemon afterwards:

−

# systemctl start mysqld

# mysql_secure_installation

# mysql_secure_installation

−

−

Then restart MySQL:

# systemctl restart mysqld

# systemctl restart mysqld

−

−

To start MySQL automatically at boot:

−

# systemctl enable mysqld

== Configuration ==

== Configuration ==

Line 29:

Line 34:

$ mysql -p -u root

$ mysql -p -u root

−

=== Enable remote access ===

+

=== Disable remote access ===

−

The MySQL server is not accessable from the network by default. To enable listing on TCP port 3306 to allow remote connections, comment out the following line in {{ic|/etc/mysql/my.cnf}}:

+

The MySQL server is accessible from the network by default. If mysql is only needed for the localhost, you can improve security by not listening on TCP port 3306. To refuse remote connections, uncomment the following line in {{ic|/etc/mysql/my.cnf}}:

skip-networking

skip-networking

+

+

You will still be able to log in from the localhost.

+

+

=== Enable auto-completion ===

+

The MySQL client completion feature is disabled by default. To enable it system-wide edit {{ic|/etc/mysql/my.cnf}}, and replace {{ic|no-auto-rehash}} by {{ic|auto-rehash}}. Completion will be enabled next time you run the MySQL client. Please note that enabling this feature can make the client initialization longer.

== Upgrading ==

== Upgrading ==

You might consider running this command after you have upgraded MySQL and started it:

You might consider running this command after you have upgraded MySQL and started it:

# mysql_upgrade -u root -p

# mysql_upgrade -u root -p

+

+

== Backup ==

+

The database can be dumped to a file for easy backup. The following shell script will do this for you, creating a {{ic|db_backup.gz}} file in the same directory as the script, containing your database dump:

See also the official [http://dev.mysql.com/doc/refman/5.6/en/mysqldump.html mysqldump page in the MySQL manual].

== Troubleshooting ==

== Troubleshooting ==

Line 67:

Line 92:

=== Reset the root password ===

=== Reset the root password ===

−

Stop the mysqld daemon

+

Stop the ''mysqld'' [[Daemons|daemon]].

−

# systemctl stop mysqld

# mysqld_safe --skip-grant-tables &

# mysqld_safe --skip-grant-tables &

Connect to the mysql server

Connect to the mysql server

Line 76:

Line 100:

mysql> FLUSH PRIVILEGES;

mysql> FLUSH PRIVILEGES;

mysql> exit

mysql> exit

−

And restart the daemon:

+

Start the ''mysqld'' daemon.

−

# systemctl restart mysqld

−

−

=== How to enable auto-completion ===

−

On Arch, the MySQL client completion feature is disabled by default. To enable it system-wide edit {{ic|/etc/mysql/my.cnf}}, and replace {{ic|no-auto-rehash}} by {{ic|auto-rehash}}. Completion will be enabled next time you run the MySQL client. Please note that enabling this feature can make the client initialization longer.

Revision as of 05:38, 26 March 2013

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

Note: MariaDB is now officially our default implementation of MySQL.It is recommended for all users to upgrade to MariaDB. MySQL will be dropped from the repositories to the AUR before 2013/4/26. See the announcement.

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 log in as root into your MySQL server:

$ mysql -p -u root

Disable remote access

The MySQL server is accessible from the network by default. If mysql is only needed for the localhost, you can improve security by not listening on TCP port 3306. To refuse remote connections, uncomment the following line in /etc/mysql/my.cnf:

skip-networking

You will still be able to log in from the localhost.

Enable auto-completion

The MySQL client completion feature is disabled by default. To enable it system-wide edit /etc/mysql/my.cnf, and replace no-auto-rehash by auto-rehash. Completion will be enabled next time you run the MySQL client. Please note that enabling this feature can make the client initialization longer.

Upgrading

You might consider running this command after you have upgraded MySQL and started it:

# mysql_upgrade -u root -p

Backup

The database can be dumped to a file for easy backup. The following shell script will do this for you, creating a db_backup.gz file in the same directory as the script, containing your database dump:

Troubleshooting

MySQL daemon cannot start

If you see something like this:

:: Starting MySQL [FAIL]

and there is no entry in the log files, you might want to check the permissions of files in the directories /var/lib/mysql and /var/lib/mysql/mysql. If the owner of files in these directories is not mysql:mysql, you should do the 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/: