- 下载二进制安装包(加速地址)
wget http://qiniudns.2fei.top/mysql/mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz
root@VM-0-3-ubuntu:~# cd /usr/local/
root@VM-0-3-ubuntu:/usr/local# wget http://qiniudns.2fei.top/mysql/mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz
安装准备
解压前 md5值校验
#官网5.7.25 MD5值
(mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz) MD5: d241f5dd6527cf1f9ff39449538c1eb1
#下载后校验
[root@VM_0_3_centos local]# md5sum mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz
d241f5dd6527cf1f9ff39449538c1eb1 mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz
注意:
安装前检查 /etc/my.cnf
or the /etc/mysql
* If you have previously installed MySQL using your operating system native package management system, such as Yum or APT, you may experience problems installing using a native binary. Make sure your previous MySQL installation has been removed entirely (using your package management system), and that any additional files, such as old versions of your data files, have also been removed. You should also check for configuration files such as `/etc/my.cnf` or the `/etc/mysql` directory and delete them.
For information about replacing third-party packages with official MySQL packages, see the related [APT guide](https://dev.mysql.com/doc/mysql-apt-repo-quick-guide/en/) or [Yum guide](https://dev.mysql.com/doc/refman/5.7/en/replace-third-party-yum.html "2.5.2 Replacing a Third-Party Distribution of MySQL Using the MySQL Yum Repository").
* MySQL has a dependency on the `libaio` library. Data directory initialization and subsequent server startup steps will fail if this library is not installed locally. If necessary, install it using the appropriate package manager. For example, on Yum-based systems:
- 依赖
- 5.7.19 以后 依赖 libnuma 库
#----------- 官网提供脚本---------------
#yum 方式
shell> yum search libaio
shell> yum install libaio
#apt 方式
shell> apt-cache search libaio
shell> apt-get install libaio1
For MySQL 5.7.19 and later: Support for Non-Uniform Memory Access (NUMA) has been added to the generic Linux build, which has a dependency now on the libnuma library; if the library has not been installed on your system, use you system's package manager to search for and install it (see the preceding item for some sample commands).
SLES 11: As of MySQL 5.7.19, the Linux Generic tarball package format is EL6 instead of EL5. As a side effect, the MySQL client bin/mysql needs libtinfo.so.5.
开始安装(参考官网)
shell> groupadd mysql
shell> useradd -r -g mysql -s /bin/false mysql
shell> cd /usr/local
#解压
shell> tar -zxvf mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz
#软连接 (别名)
shell> ln -s mysql-5.7.25-linux-glibc2.12-x86_64 mysql
shell> cd mysql
shell> mkdir mysql-files
shell> chown mysql:mysql mysql-files
shell> chmod 750 mysql-files
#注意生成的临时密码 A temporary password is generated for root@localhost: mj)A.o%ey4n7
# 初始化不指定密码 bin/mysqld --initialize-insecure --user=mysql
shell> bin/mysqld --initialize --user=mysql
#生成ssl
shell> bin/mysql_ssl_rsa_setup
# mysqld_safe 方式启动
shell> bin/mysqld_safe --user=mysql &
# Next command is optional (可选 )
#
shell> cp support-files/mysql.server /etc/init.d/mysql.server
- 添加环境变量
vim /etc/profile
# 追加path
export PATH=/usr/local/mysql/bin:$PATH
#重启
source /etc/profile
root@VM-0-3-ubuntu:/usr/local# source /etc/profile
- 启动mysql(启动/重启/停止)
/etc/init.d/mysql.server start / restart / stop
root@VM-0-3-ubuntu:/usr/local# /etc/init.d/mysql.server start
[ ok ] Starting mysql.server (via systemctl): mysql.server.service.
#查看mysql 后台进程
root@VM-0-3-ubuntu:/usr/local# ps -ef|grep mysqld
root 9422 1 0 10:35 ? 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/VM-0-3-ubuntu.pid
mysql 9521 9422 0 10:35 ? 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=VM-0-3-ubuntu.err --pid-file=/usr/local/mysql/data/VM-0-3-ubuntu.pid
root 10210 7484 0 10:40 pts/2 00:00:00 grep --color=auto mysqld
root@VM-0-3-ubuntu:/usr/local#
- 登陆mysql
--修改密码
mysql> set password=password('root');
--设置root账户的host地址(修改了才可以远程连接)
mysql>grant all privileges on *.* to 'root'@'%' identified by 'root';
mysql>flush privileges;
mysql root密码忘记了?
1. 挂维护页
2. 关数据库
root@VM-0-3-ubuntu:~# /etc/init.d/mysql.server stop
3. 跳过授权启动
root@VM-0-3-ubuntu:~# mysqld_safe --skip-grant-tables --skip-networking &
--skip-grant-tables : 连接层关闭验证模块,所有验证表不加载。
--skip-networking :连接层关闭TCP/IP协议,禁止远程访问。
4. 改密码
mysql> alter user root@'localhost' identified by '456';
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
mysql>
mysql>
mysql>
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> alter user root@'localhost' identified by '456';
Query OK, 0 rows affected (0.00 sec)
mysql>exit;
5.正常开启业务
关于初始化的新特性(5.6 和 5.7 )
5.6 版本的初始化程序:
/data/mysql/scripts/mysql_install_db --user=mysql --basedir=/data/mysql --datadir=/data/mysql/data
初始化完成后:无密码和无安全策略的
5.7 版本的初始化程序:
(1)
/data/mysql/bin/mysqld --initialize --user=mysql --basedir=/data/mysql --datadir=/data/mysql/data
(2)
/data/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/data/mysql --datadir=/data/mysql/data
提示:5.7以后初始化命令变为bin/mysqld命令,提供了两种初始化方式
第一种初始化方式:开启临时密码和安全策略
第二种初始化方式和之前版本一样,是无密码无安全策略。
演示:
2019-04-03T03:40:15.595883Z 1 [Note] A temporary password is generated for root@localhost: **MWht)!4%sa,3**
安全策略?
密码的复杂度进行了要求,对于密码的过期时间设置了限制