Difference between revisions of "MySQL"
Kynikos.bot (talk | contribs) (Template:i18n is deprecated, use interlanguage links, see Help talk:I18n#"Dummy" interlanguage links and deprecation of Template:i18n) |
m (→More Resources: Add Mariadb page link.) |
||
(20 intermediate revisions by 9 users not shown) | |||
Line 1: | Line 1: | ||
− | |||
[[Category:Database management systems]] | [[Category:Database management systems]] | ||
[[cs:MySQL]] | [[cs:MySQL]] | ||
Line 9: | Line 8: | ||
[[tr:MySQL]] | [[tr:MySQL]] | ||
[[zh-CN:MySQL]] | [[zh-CN:MySQL]] | ||
− | |||
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]. | ||
== Installation == | == Installation == | ||
− | Install the {{Pkg|mysql}} package | + | [[pacman|Install]] the {{Pkg|mysql}} package from the [[Official Repositories|official repositories]]. |
− | After installing MySQL, | + | After installing MySQL, [[Daemons#Starting manually|start]] the mysqld daemon and run the setup script: |
− | # | + | # mysql_secure_installation |
− | Then restart MySQL | + | Then [[Daemons#Restarting|restart]] MySQL (mysqld). If you want to start MySQL at boot time, see [[Daemons#Starting on boot]]. |
− | |||
− | |||
− | |||
− | |||
− | |||
== Configuration == | == Configuration == | ||
Line 29: | Line 22: | ||
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: | 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 | $ mysql -p -u root | ||
− | |||
− | |||
=== Enable remote access === | === Enable remote access === | ||
− | The MySQL server | + | 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}}: |
skip-networking | skip-networking | ||
+ | |||
+ | === 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 | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
== Troubleshooting == | == Troubleshooting == | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
=== MySQL daemon cannot start === | === MySQL daemon cannot start === | ||
If you see something like this: | If you see something like this: | ||
− | |||
− | |||
:: Starting MySQL [FAIL] | :: Starting MySQL [FAIL] | ||
and there is no entry in the log files, you might want to check the permissions of files in the directories {{ic|/var/lib/mysql}} and {{ic|/var/lib/mysql/mysql}}. If the owner of files in these directories is not {{ic|mysql:mysql}}, you should do the following: | and there is no entry in the log files, you might want to check the permissions of files in the directories {{ic|/var/lib/mysql}} and {{ic|/var/lib/mysql/mysql}}. If the owner of files in these directories is not {{ic|mysql:mysql}}, you should do the following: | ||
Line 108: | Line 42: | ||
If you run into permission problems despite having followed the above, ensure that your {{ic|my.cnf}} is copied to {{ic|/etc/}}: | If you run into permission problems despite having followed the above, ensure that your {{ic|my.cnf}} is copied to {{ic|/etc/}}: | ||
# cp /etc/mysql/my.cnf /etc/my.cnf | # cp /etc/mysql/my.cnf /etc/my.cnf | ||
− | Now try and | + | Now try and start the daemon. |
If you get these messages in your {{ic|/var/lib/mysql/hostname.err}} | If you get these messages in your {{ic|/var/lib/mysql/hostname.err}} | ||
Line 114: | Line 48: | ||
[ERROR] Do you already have another mysqld server running on socket: /var/run/mysqld/mysqld.sock ? | [ERROR] Do you already have another mysqld server running on socket: /var/run/mysqld/mysqld.sock ? | ||
[ERROR] Aborting | [ERROR] Aborting | ||
− | + | The permissions of {{ic|/var/run/mysqld}} could be the culprit. | |
# chown mysql:mysql /var/run/mysqld -R | # chown mysql:mysql /var/run/mysqld -R | ||
+ | |||
If you run mysqld and the following error appears: | If you run mysqld and the following error appears: | ||
Fatal error: Can’t open and lock privilege tables: Table ‘mysql.host’ doesn’t exist | Fatal error: Can’t open and lock privilege tables: Table ‘mysql.host’ doesn’t exist | ||
Line 122: | Line 57: | ||
# mysql_install_db --user=mysql --ldata=/var/lib/mysql/ | # mysql_install_db --user=mysql --ldata=/var/lib/mysql/ | ||
− | === Unable to run mysql_upgrade because MySQL cannot start | + | === Unable to run mysql_upgrade because MySQL cannot start === |
Try run MySQL in safemode: | Try run MySQL in safemode: | ||
# mysqld_safe --datadir=/var/lib/mysql/ | # mysqld_safe --datadir=/var/lib/mysql/ | ||
Line 128: | Line 63: | ||
# mysql_upgrade -u root -p | # mysql_upgrade -u root -p | ||
− | === | + | === Reset the root password === |
− | Stop | + | [[Daemons#Starting_manually|Stop]] mysqld |
− | |||
# mysqld_safe --skip-grant-tables & | # mysqld_safe --skip-grant-tables & | ||
Connect to the mysql server | Connect to the mysql server | ||
Line 138: | Line 72: | ||
mysql> FLUSH PRIVILEGES; | mysql> FLUSH PRIVILEGES; | ||
mysql> exit | mysql> exit | ||
− | + | [[Daemons#Starting_manually|Start]] mysqld. | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | == | + | == See also == |
+ | * [[MariaDB]] | ||
* [[LAMP]] - Arch wiki article covering the setup of a LAMP server (Linux Apache MySQL PHP) | * [[LAMP]] - Arch wiki article covering the setup of a LAMP server (Linux Apache MySQL PHP) | ||
* http://www.mysql.com/ | * http://www.mysql.com/ | ||
* Front-ends: {{AUR|mysql-gui-tools}} {{AUR|mysql-workbench}} | * Front-ends: {{AUR|mysql-gui-tools}} {{AUR|mysql-workbench}} |
Revision as of 12:53, 2 January 2013
zh-CN: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 from the official repositories.
After installing MySQL, start the mysqld daemon and run the setup script:
# mysql_secure_installation
Then restart MySQL (mysqld). If you want to start MySQL at boot time, see Daemons#Starting on boot.
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
Enable 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 /etc/mysql/my.cnf
:
skip-networking
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
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/
:
# cp /etc/mysql/my.cnf /etc/my.cnf
Now try and start the daemon.
If you get these messages in your /var/lib/mysql/hostname.err
[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
The permissions of /var/run/mysqld
could be the culprit.
# 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 from the /usr directory to install the default tables:
# cd /usr # 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
Reset the root password
Stop mysqld
# mysqld_safe --skip-grant-tables &
Connect to the 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
Start mysqld.
See also
- MariaDB
- LAMP - Arch wiki article covering the setup of a LAMP server (Linux Apache MySQL PHP)
- http://www.mysql.com/
- Front-ends: mysql-gui-toolsAUR mysql-workbenchAUR