mysql5.7 二进制包安装

首先下载安装包

[[email protected]:/usr/local/src#] wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz
--2018-04-07 14:33:19--  http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz

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

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

初始化

[[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.131176Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-04-07T06:51:29.587196Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-04-07T06:51:29.734116Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-04-07T06:51:29.799182Z 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: 19a69ffc-3a30-11e8-98be-525400ab1246.
2018-04-07T06:51:29.800743Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
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
Generating a 2048 bit RSA private key
.....+++
...+++
writing new private key to 'ca-key.pem'
-----
Generating a 2048 bit RSA private key
............................+++
.....+++
writing new private key to 'server-key.pem'
-----
Generating a 2048 bit RSA private key
..................+++
.......+++
writing new private key to 'client-key.pem'
-----
#注意 "[email protected]" 后面有一串 ",SPDv;b;(6M_" 乱码,这串乱码就是 root 用户的默认登陆密码

拷贝配置文件和启动脚本

[[email protected]:/usr/local/mysql#] cp support-files/my-default.cnf  /etc/my.cnf
cp: overwrite ‘/etc/my.cnf’? y
[[email protected]:/usr/local/mysql#] vim /etc/my.cnf
  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
root     13552  0.0  0.0 112648   964 pts/0    R+   15:08   0:00 grep --color=auto mysql

登陆 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.17 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.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.
#修改配置文件 "my.cnf",在 "[mysqld]" 模块下添加 "skip-grant-tables",重启 Mysql,然后不用密码登陆 Mysql,使用 update 语句修改 root 密码,然后退出 Mysql,再把配置文件 "my.cnf" 的 "skip-grant-tables" 注释掉,然后重启 Mysql,使用新密码登陆 Mysql

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

mysqlmysql5.7二进制包

我来吐槽

*

*