首先下载安装包

[root@LZWP:/usr/local/src#] wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.27-linux-glibc2.12-x86_64.tar.gz

解压并剪切到 /usr/local/ 目录下并重命名为 mysql

[root@LZWP:/usr/local/src#] tar xvf mysql-5.7.27-linux-glibc2.12-x86_64.tar.gz
[root@LZWP:/usr/local/src#] mv mysql-5.7.27-linux-glibc2.12-x86_64 /usr/local/mysql

删除系统自带的 maraiadb 和做 mysql 的初始化

[root@LZWP:/usr/local/src#] yum -y remove maraia*
[root@LZWP:/usr/local/src#] cd /usr/local/mysql/
[root@LZWP:/usr/local/mysql#] useradd -M -s /sbin/nologin mysql
[root@LZWP:/usr/local/mysql#] mkdir -p /data/mysql
[root@LZWP:/usr/local/mysql#] chown mysql:mysql /data/mysql
[root@LZWP:/usr/local/mysql#] ./bin/mysqld  --initialize --user=mysql --datadir=/data/mysql
2018-04-07T06:51:29.801322Z 1 [Note] A temporary password is generated for root@localhost: ,SPDv;b;(6M_
[root@LZWP:/usr/local/mysql#] ./bin/mysql_ssl_rsa_setup --datadir=/data/mysql
#注意 "root@localhost" 后面有一串 ",SPDv;b;(6M_" 乱码,这串乱码就是 root 用户的默认登陆密码

编写配置文件和启动脚本

[root@LZWP:/usr/local/mysql#] vim /etc/my.cnf
[mysqld]
basedir = /usr/local/mysql
datadir = /data/mysql
port = 3306
socket = /tmp/mysql.sock
[root@LZWP:/usr/local/mysql#] cp support-files/mysql.server /etc/init.d/mysqld
[root@LZWP:/usr/local/mysql#] vim /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/data/mysql

启动 Mysql 服务

[root@LZWP:/usr/local/mysql#] cd bin/
[root@LZWP:/usr/local/mysql/bin#] pwd
/usr/local/mysql/bin
[root@LZWP:/usr/local/mysql/bin#] vim /etc/profile
export PATH=$PATH:/usr/local/mysql/bin
[root@LZWP:/usr/local/mysql/bin#] source /etc/profile
[root@LZWP:/usr/local/mysql/bin#] chkconfig --add mysqld
[root@LZWP:/usr/local/mysql/bin#] chkconfig mysqld on
[root@LZWP:/usr/local/mysql/bin#] service mysqld start
Starting MySQL.Logging to '/data/mysql/LZWP.err'.
 SUCCESS! 
[root@LZWP:/usr/local/mysql/bin#] ps -aux | grep mysql
root     13358  0.0  0.1  11764  1604 pts/0    S    15:07   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/LZWP.pid
mysql    13516  2.2 17.4 1118644 177404 pts/0  Sl   15:07   0:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/LZWP.err --pid-file=/data/mysql/LZWP.pid --socket=/tmp/mysql.sock --port=3306

登陆 Mysql,修改 root 默认密码(这里输入自动生成的那个默认密码)

[root@LZWP:/usr/local/mysql/bin#] mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.17
Copyright (c) 2000, 2016, 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>set password = password('123456');

问题点

[root@LZWP:/usr/local/mysql/bin#] mysql -uroot -p',SPDv;b;(6M_;'
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
#以这种方式登陆 Mysql 的时候提示有问题

[root@LZWP:/usr/local/mysql/bin#] vim /etc/my.cnf
[mysqld]
skip-grant-tables
[root@LZWP:/usr/local/mysql/bin#] service mysqld restart
Shutting down MySQL.. SUCCESS! 
Starting MySQL. SUCCESS!
[root@LZWP:/usr/local/mysql/bin#] mysql -uroot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.27 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, 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> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> update user set authentication_string=password('123456') where user='root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1
mysql> quit
Bye
[root@LZWP:/usr/local/mysql/bin#] vim /etc/my.cnf
[mysqld]
#skip-grant-tables
[root@LZWP:/usr/local/mysql/bin#] service mysqld restart
Shutting down MySQL.. SUCCESS! 
Starting MySQL. SUCCESS! 
[root@LZWP:/usr/local/mysql/bin#] mysql -uroot -p'123456'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.27
Copyright (c) 2000, 2016, 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.
#修改配置文件 "my.cnf",在 "[mysqld]" 模块下添加 "skip-grant-tables",重启 Mysql,然后不用密码登陆 Mysql,使用 update 语句修改 root 密码,然后退出 Mysql,再把配置文件 "my.cnf" 的 "skip-grant-tables" 注释掉,然后重启 Mysql,使用新密码登陆 Mysql

开启 root 用户远程访问权限

use mysql;
update user set host='%' where user='root';
FLUSH PRIVILEGES

到此~Mysql5.7二进制包安装完成!


文章作者: Runfa Li
本文链接:
版权声明: 本站所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 Linux 小白鼠
Linux Linux mysql mysql5.7
觉得文章不错,打赏一点吧,1分也是爱~
打赏
微信 微信
支付宝 支付宝