mysql 5.7 二进制安装方法

时间:2021-10-07 20:57:59
shell> groupadd mysql
shell> useradd -r -g mysql -s /bin/false mysql
shell> cd /usr/localshell> tar zxvf /path/to/mysql-VERSION-OS.tar.gzshell> ln -s full-path-to-mysql-VERSION-OS mysqlshell> cd mysqlshell> mkdir mysql-filesshell> chmod 750 mysql-filesshell> chown -R mysql .shell> chgrp -R mysql .shell> bin/mysql_install_db --user=mysql    # Before MySQL 5.7.6shell>./bin/mysqld --initialize --user=mysql --datadir=/home/mysql/mysql3316/data/ # MySQL 5.7.6 and up
2016-08-03T09:04:12.255526Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-08-03T09:04:12.538185Z 0 [Warning] InnoDB: New log files created, LSN=45790
2016-08-03T09:04:12.592864Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2016-08-03T09:04:12.605358Z 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: 3f0b6c52-5959-11e6-8c68-00163e415703.
2016-08-03T09:04:12.606217Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2016-08-03T09:04:12.607201Z 1 [Note] A temporary password is generated for root@localhost: w+&E:13EZDnq

shell>./bin/mysql_ssl_rsa_setup --datadir=/home/mysql/mysql3316/data/ # MySQL 5.7.6 and up
shell> chown -R root .shell> chown -R mysql data mysql-filesshell> bin/mysqld_safe --user=mysql &# Next command is optionalshell> cp support-files/mysql.server /etc/init.d/mysql.server
 
shell> mysql -uroot -p'w+&E:13EZDnq' -hlocalhost --socket=/tmp/mysql3316.sock --port=3316
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> set password = password('mypass');   //一定要设置一下新密码
 
还有一种情况,就是不知道初始化密码
vi /etc/my.cnf
在[mysqld]下面增加一行
skip-grant-tables
重启  /etc/init.d/mysqld restart

/usr/local/mysql/bin/mysql -uroot 
mysql> update user set authentication_string=password('123333') where user='root';
退出来后,更改my.cnf,去掉刚加的 skip-grant-tables
重启 /etc/init.d/mysqld restart

此时就可以使用新的密码了。