环境介绍>>>>>>>>>>>>>>>>>>
操作系统:Centos 7.1
mysql数据库版本:mysql5.7.9
------------------------------------------
1、安装新版mysql之前,我们需要将系统自带的mariadb-lib卸载[[email protected] ~]# rpm -qa|grep mariadb
mariadb-libs-5.5.41-2.el7_0.x86_64
[[email protected] ~]# rpm -e mariadb-libs-5.5.41-2.el7_0.x86_64 --nodeps
2、到mysql的官网下载最新版mysql的rpm集合包:mysql-5.7.9-1.el7.x86_64.rpm-bundle.tar
3、上传mysql-5.7.9-1.el7.x86_64.rpm-bundle.tar到linux服务器,并解压tar包
[[email protected] mysql]# mkdir RPM
rz waiting to receive.
Starting zmodem transfer. Press Ctrl+C to cancel.
Transferring mysql-5.7.18-1.el7.x86_64.rpm-bundle.tar...
100% 570950 KB 8274 KB/sec 00:01:09 0 Errors
mysql-5.7.18-1.el7.x86_64.rpm-bundle.tar
[[email protected] RPM]# tar -xf mysql-5.7.18-1.el7.x86_64.rpm-bundle.tar
mysql-5.7.18-1.el7.x86_64.rpm-bundle.tar mysql-community-libs-5.7.18-1.el7.x86_64.rpm
mysql-community-client-5.7.18-1.el7.x86_64.rpm mysql-community-libs-compat-5.7.18-1.el7.x86_64.rpm
mysql-community-common-5.7.18-1.el7.x86_64.rpm mysql-community-minimal-debuginfo-5.7.18-1.el7.x86_64.rpm
mysql-community-devel-5.7.18-1.el7.x86_64.rpm mysql-community-server-5.7.18-1.el7.x86_64.rpm
mysql-community-embedded-5.7.18-1.el7.x86_64.rpm mysql-community-server-minimal-5.7.18-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.18-1.el7.x86_64.rpm mysql-community-test-5.7.18-1.el7.x86_64.rpm
mysql-community-embedded-devel-5.7.18-1.el7.x86_64.rpm
4、其中最简单的安装mysql-server服务,只需要安装如下4个软件包即可,我们可以使用rpm -ivh命令进行安装
mysql-community-common-5.7.9-1.el7.x86_64.rpm
mysql-community-libs-5.7.9-1.el7.x86_64.rpm --(依赖于common)
mysql-community-client-5.7.9-1.el7.x86_64.rpm --(依赖于libs)
mysql-community-server-5.7.9-1.el7.x86_64.rpm --(依赖于client、common)
5、接下来是初始化数据库,我们使用如下几条命令均可,效果都是一样的[[email protected] ~]# mysql_install_db --datadir=/var/lib/mysql //必须指定datadir,执行后会生成~/.mysql_secret密码文件[[email protected] ~]# mysqld --initialize //新版的推荐此方法,执行生会在/var/log/mysqld.log生成随机密码
6、更改mysql数据库目录的所属用户及其所属组,然后启动mysql数据库[[email protected] ~]# chown mysql:mysql /var/lib/mysql -R
[[email protected] ~]# systemctl start mysqld.service //启动mysql数据库服务
7、根据第5步中的密码登录到mysql,更改root用户的密码,新版的mysql在第一次登录后更改密码前是不能执行任何命令的[[email protected] ~]# mysql -uroot -p')j#)=uRig4yJ'mysql> set password=password('www.cnblogs.com/5201351');
8、最后我们还可以根据实际情况创建用户,及作权限分配mysql> create user 'root'@'192.168.100.2' identified by 'QQ5201351';
mysql> GRANT ALL PRIVILEGES ON dbname.* to 'root'@'192.168.100.2';
mysql> flush privileges
==============================================
最后需要特别提醒注意的一点是,新版的mysql数据库下的user表中已经没有Password字段了,
而是将加密后的用户密码存储于authentication_string字段