mysql5.7 二进制包安装

首先下载安装包

[[email protected]:/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

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

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

[[email protected]:/usr/local/src#] yum -y remove maraia*
[[email protected]:/usr/local/src#] cd /usr/local/mysql/
[[email protected]:/usr/local/mysql#] useradd -M -s /sbin/nologin mysql
[[email protected]:/usr/local/mysql#] mkdir -p /data/mysql
[[email protected]:/usr/local/mysql#] chown mysql:mysql /data/mysql
[[email protected]:/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 [email protected]: ,SPDv;b;(6M_
[[email protected]:/usr/local/mysql#] ./bin/mysql_ssl_rsa_setup --datadir=/data/mysql
#注意 "[email protected]" 后面有一串 ",SPDv;b;(6M_" 乱码,这串乱码就是 root 用户的默认登陆密码

编写配置文件和启动脚本

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

启动 Mysql 服务

[[email protected]:/usr/local/mysql#] cd bin/
[[email protected]:/usr/local/mysql/bin#] pwd
/usr/local/mysql/bin
[[email protected]:/usr/local/mysql/bin#] vim /etc/profile
export PATH=$PATH:/usr/local/mysql/bin
[[email protected]:/usr/local/mysql/bin#] source /etc/profile
[[email protected]:/usr/local/mysql/bin#] chkconfig --add mysqld
[[email protected]:/usr/local/mysql/bin#] chkconfig mysqld on
[[email protected]:/usr/local/mysql/bin#] service mysqld start
Starting MySQL.Logging to '/data/mysql/LZWP.err'.
 SUCCESS! 
[[email protected]:/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 默认密码(这里输入自动生成的那个默认密码)

[[email protected]:/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');

问题点

[[email protected]:/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 的时候提示有问题

[[email protected]:/usr/local/mysql/bin#] vim /etc/my.cnf
[mysqld]
skip-grant-tables
[[email protected]:/usr/local/mysql/bin#] service mysqld restart
Shutting down MySQL.. SUCCESS! 
Starting MySQL. SUCCESS!
[[email protected]:/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
[[email protected]:/usr/local/mysql/bin#] vim /etc/my.cnf
[mysqld]
#skip-grant-tables
[[email protected]:/usr/local/mysql/bin#] service mysqld restart
Shutting down MySQL.. SUCCESS! 
Starting MySQL. SUCCESS! 
[[email protected]:/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二进制包安装完成!

mysqlmysql5.7二进制包

我来吐槽

*

*