shell> bin/mysql_install_db --user=mysql # Before MySQL 5.7.6 shell> bin/mysqld --initialize --user=mysql # MySQL 5.7.6 and up shell> bin/mysql_ssl_rsa_setup # MySQL 5.7.6 and up
初始化数据库 shell># bin/mysqld --initialize --user=mysql 2015-11-13T03:35:03.910909Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2015-11-13T03:35:04.051875Z 0 [Warning] InnoDB: New log files created, LSN=45790 2015-11-13T03:35:04.081030Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2015-11-13T03:35:04.134482Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 86fbe8f6-89b7-11e5-aacd-c81f66f10582. 2015-11-13T03:35:04.134868Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2015-11-13T03:35:04.135431Z 1 [Note] A temporary password is generated for root@localhost: nwpD(-Nap1r2 shell># bin/mysql_ssl_rsa_setup Generating a 2048 bit RSA private key .....................+++ .....................+++ writing new private key to 'ca-key.pem' ----- Generating a 2048 bit RSA private key .................................................................................+++ ...........................+++ writing new private key to 'server-key.pem' ----- Generating a 2048 bit RSA private key .....................+++ ...............................+++ writing new private key to 'client-key.pem' ----- shell># chown -R root . shell># ll total 160 drwxr-xr-x 2 root mysql 4096 Oct 12 15:30 bin -rw-r--r-- 1 root mysql 17987 Oct 12 14:21 COPYING drwxr-xr-x 2 root mysql 4096 Oct 12 15:30 docs drwxr-xr-x 3 root mysql 4096 Oct 12 15:30 include -rw-r--r-- 1 root mysql 108028 Oct 12 14:21 INSTALL-BINARY drwxr-xr-x 5 root mysql 4096 Oct 12 15:30 lib drwxr-xr-x 4 root mysql 4096 Oct 12 15:29 man -rw-r--r-- 1 root mysql 2478 Oct 12 14:21 README drwxr-xr-x 28 root mysql 4096 Oct 12 15:30 share drwxr-xr-x 2 root mysql 4096 Nov 13 11:32 support-files shell># chown -R mysql /home/mysql
后台启动MySQL shell># bin/mysqld_safe --user=mysql & [1] 32559 shell># 151113 11:36:12 mysqld_safe Logging to '/home/mysql/mysqld.log'. 151113 11:36:12 mysqld_safe Starting mysqld daemon with databases from /home/mysql
shell># mysql -bash: mysql: command not found 增加环境变量 shell># vi .bash_profile
# .bash_profile
# Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin:/usr/local/mysql/bin
export PATH ~
shell># source .bash_profile
mysql -uroot -p -S /home/mysql/mysql.sock Enter password:
mysql> show databases; ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> ALTER USER 'root'@'localhost' IDENTIFIED by 'oraclemysql'; Query OK, 0 rows affected (0.00 sec)
启动脚本,设置开机自启动 shell># cd /usr/local/mysql shell># cp support-files/mysql.server /etc/init.d/mysql shell># /etc/init.d/mysql status MySQL running (33907)[ OK ] shell># chkconfig --list|grep mysql shell># chkconfig --add mysql shell># chkconfig --list|grep mysql mysql 0:off 1:off 2:on 3:on 4:on 5:on 6:off
测试安装是否正常 shell># service mysql stop Shutting down MySQL..[ OK ] shell># service mysql start Starting MySQL.[ OK ] shell># mysql ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) shell># mysql -S /home/mysql/mysql.sock -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or /g. Your MySQL connection id is 2 Server version: 5.7.9 MySQL Community Server (GPL)
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.
Type 'help;' or '/h' for help. Type '/c' to clear the current input statement.
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.00 sec)