标签:generated 二进制 password 字符串 local
1. 下载包
wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.10-linux-glibc2.5-x86_64.tar.gz
2. 解压
tar zxvf mysql-5.7.10-linux-glibc2.5-x86_64.tar.gz
mv mysql-5.7.10-linux-glibc2.5-x86_64 /usr/local/mysql
3. 初始化
useradd -M -s /sbin/nologin mysql ---建立用户
mkdir -p /data/mysql
chown mysql /data/mysql
cd /usr/local/mysql
./bin/mysqld --initialize --user=mysql --datadir=/data/mysql
注意,这一步最后一行会有一个提示
[Note] A temporary password is generated for root@localhost: B*s1i(*,kXwg
最后面的字符串为root密码。
./bin/mysql_ssl_rsa_setup --datadir=/data/mysql
4. 拷贝配置文件和启动脚本
cp support-files/my-default.cnf /etc/my.cnf
vim /etc/my.cnf //编辑或者修改
basedir = /usr/local/mysql
datadir = /data/mysql
port = 3306
socket = /tmp/mysql.sock
cp support-files/mysql.server /etc/init.d/mysqld
vi /etc/init.d/mysqld //编辑或者修改
basedir=/usr/local/mysql
datadir=/data/mysql
chmod 755 /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
5. 启动服务
/etc/init.d/mysqld start
6. 设置root密码
使用初始化密码登录
/usr/local/mysql/bin/mysql -uroot -p‘B*s1i(*,kXwg‘ //进入后直接设置密码
mysql>set password = password(‘mypass‘); //一定要设置一下新密码
退出来,再使用新的密码登录就可以了
还有一种情况,就是不知道初始化密码
vi /etc/my.cnf
在[mysqld]下面增加一行
skip-grant-tables
重启 /etc/init.d/mysqld restart
/usr/local/mysql/bin/mysql -uroot
use mysql
mysql> update user set authentication_string=password(‘123333‘) where user=‘root‘;
退出来后,更改my.cnf,去掉刚加的 skip-grant-tables
重启 /etc/init.d/mysqld restart
此时就可以使用新的密码了。
错误:ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
办法:
flush privileges;
错误:error 1820 (hy000): you must reset your password using alter user statement
办法:
# /etc/init.d/mysql stop
# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
# mysql -u root mysql
mysql> UPDATE user SET Password=PASSWORD(‘newpassword‘) where USER=‘root‘;
mysql> FLUSH PRIVILEGES;
mysql> quit
# /etc/init.d/mysql restart
# mysql -uroot -p
Enter password: <输入新设的密码newpassword>
标签:generated 二进制 password 字符串 local
原文地址:http://11706174.blog.51cto.com/11696174/1787450