MySQL: FAQs
1. Install MySQL on Linux
Installation steps:
1) decompress the tar.gz File
shell> tar -zxvf mysql-5.7.9-linux-glibc2.5-x86_64.tar.gz
2) initialize the default database (mysql, performace_schema, sys, and information_schema)
The structure in the/home/bes/jinuo/mysql directory is as follows:
/home/bes/jinuo/mysql /mysql-5.7.9-glibc2.5-x86_64 /bin /docs /include /lib /man /share /support-files /test /ins1 /my-default.cnf
Copy the support-files directory to the directory where you want to create a mysql instance and edit it as follows:
[mysqld]basedir=/home/bes/jinuo/mysql/mysql-5.7.9-linux-glibc2.5-x86_64datadir=/home/bes/jinuo/mysql/test/ins1/datadirport=36001server_id=36001socket=/home/bes/jinuo/mysql/test/ins1/mysql.socklog-error=/home/bes/jinuo/mysql/test/mysqld.logexplicit_defaults_for_timestamp=truecharacter-set-server=utf8collation-server=utf8_general_ciskip-host-cachesql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
Then execute the following command to initialize:
shell> bin/mysql_install_db # Before MySQL 5.7.6shell> bin/mysqld --initialize # MySQL 5.7.6 and up
During initialization, a temporary password is created for the root user. The location of the temporary password can be found as follows:
MySQL 5.6.x :
A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER !You will find that password in '/root/.mysql_secret'.You must change that password on your first connect,no other statement but 'SET PASSWORD' will be accepted.See the manual for the semantics of the 'password expired' flag.Also, the account for the anonymous user has been removed.
MySQL 5.7.x:
If -- initialize:
# Tail-n1/home/bes/jinuo/mysql/test/ins1/mysqld. log2016-12-11T07: 47: 58.199154Z 1 [Note] A temporary password is generated for root @ localhost: wzgds/: Kf2, g
If
-- Initialize-insecure:
# Tail-n1/var/log/mysql/error. log
2016-12-11T07: 51: 28.506142Z 1 [Warning] root @ localhost is created with an empty password! Please consider switching off the -- initialize-insecure option
3) Start the database
Start MySQL Server:
shelll> /home/bes/jinuo/mysql/mysql-5.7.9-linux-glibc2.5-x86_64/bin/mysqld --defaults-file=/home/bes/jinuo/mysql/test/ins1/my-default.cnf &
4) modify the root password and authorization
A: Stop MySQL Server.
B: Start MySQL Server by bypassing the authorization Check Method
shell> /home/bes/jinuo/mysql/mysql-5.7.9-linux-glibc2.5-x86_64/bin/mysqld --defaults-file=/home/bes/jinuo/mysql/test/ins1/my-default.cnf --skip-grant-tables &
C: the root user logs on to the mysql server and switches to the mysql database.
shell> /home/bes/jinuo/mysql/mysql-5.7.9-linux-glibc2.5-x86_64/bin/mysql --socket=/home/bes/jinuo/mysql/test/ins1/mysql.sock -uroot -p
mysql> use mysql;
D: Modify the password of the root user:
mysql> update mysql.user set authentication_string = password('mypassword') where user = 'root';
mysql> flush privileges;
mysql> quit;
E: Stop the mysql server and start it normally.
The normal start method is described in the previous 3.
F: After the root user logs on, adjust the authorization:
shell> /home/bes/jinuo/mysql/mysql-5.7.9-linux-glibc2.5-x86_64/bin/mysql --socket=/home/bes/jinuo/mysql/test/ins1/mysql.sock -uroot -pEnter Passwordmysql> grant all on *.* to 'root'@'%' identified by 'yourRootPassword';