MySQL安装
本文档为mysql安装手册 v1.0版本
最新方式安装mysql方式
检查是否已经安装mysql(两种方式)
[root@master ~]# rpm -qa | grep mysql [root@master ~]# yum list installed | grep mysql
centos 7 下需要删除mariadb
检查:
[root@master ~]# rpm -qa | grep mariadb
删除如下:强制删除
如果已经安装,卸载掉原mysql
[root@master ~]# rpm -e mysql 【一般删除,如果提示依赖的其他文件,则不能删除】 [root@master ~]# rpm -e --nodeps mysql 【强力删除,包含各种依赖包】
第二种方式删除
删除 MySQL 及其依赖的包
[root@master ~]# yum remove mysql-*
查询遗留目录:
[root@master ~]# ls /etc/my.cnf(一般情况都没用这个) /etc/my.cnf [root@master ~]# ll /var/lib/mysql/ total 28700 -rw-rw---- 1 mysql mysql 16384 May 5 10:31 aria_log.00000001 -rw-rw---- 1 mysql mysql 52 May 5 10:31 aria_log_control -rw-rw---- 1 mysql mysql 18874368 May 5 10:31 ibdata1 -rw-rw---- 1 mysql mysql 5242880 May 5 10:31 ib_logfile0 -rw-rw---- 1 mysql mysql 5242880 Oct 6 2017 ib_logfile1 drwx------ 2 mysql mysql 4096 Oct 6 2017 mysql drwx------ 2 mysql mysql 4096 Oct 6 2017 performance_schema
删除遗留目录:
[root@master ~]# rm -rf /etc/my.cnf [root@master ~]# rm -rf /var/lib/mysql/
下载 mysql57-community-release-el7-9.noarch.rpm 的 YUM 源:
[root@master ~]# wget http://repo.mysql.com/mysql57-community-release-el7-9.noarch.rpm
** 如果无法在centos中通过wget方式下载下来,就在本地电脑中将此文件下载下来,上传到centos中**
安装 mysql57-community-release-el7-9.noarch.rpm:
[root@master ~]# yum -y localinstall mysql57-community-release-el7-9.noarch.rpm
安装 mysql-server
[root@master ~]# yum -y install mysql-community-server --nogpgcheck
安装完毕后,运行mysql,启动mysql服务:
[root@master ~]# systemctl start mysqld
然后在 /var/log/mysqld.log 文件中会自动生成一个随机的密码,我们需要先取得这个随机密码,以用于登录 MySQL 服务端:
[root@master ~]# grep "password" /var/log/mysqld.log
将会返回如下内容,末尾字符串就是密码,把它复制下来
A temporary password is generated for root@localhost: hilX0U!9i3_6
登录到 MySQL 服务端并更新用户 root 的密码:
注意:由于 MySQL5.7 采用了密码强度验证插件 validate_password,故此我们需要设置一个有一定强度的密码;
[root@master ~]# mysql -u root -p hilX0U!9i3_6
关闭强密码验证:(如果要设置简单密码,登录mysql前执行此步骤,退出mysql:exit)
[root@master ~]# vim /etc/my.cnf 在文件的后面添加以下内容 plugin-load=validate_password.so validate-password=OFF 重启mysql [root@master ~]# systemctl restart mysqld
更改密码
mysql> SET PASSWORD = PASSWORD('your new password'); mysql> ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER; mysql> flush privileges;
查询用户表
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> select User,authentication_string,Host from user; +---------------+-------------------------------------------+-----------+ | User | authentication_string | Host | +---------------+-------------------------------------------+-----------+ | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | localhost | | mysql.session | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | localhost | | mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | localhost | | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | % | +---------------+-------------------------------------------+-----------+ 4 rows in set (0.00 sec) mysql>
设置用户 root 可以在任意 IP 下被访问:
mysql> grant all privileges on *.* to root@"%" identified by "new password"; 设置用户 root 可以在本地被访问: mysql> grant all privileges on *.* to root@"localhost" identified by "new password"; 刷新权限使之生效: mysql> flush privileges; 退出MySQL: mysql> exit
设置开机启动MySQL服务(完成这步,mysql基本搞定了)
>>> systemctl enable mysqld
扩展(优化及问题解决方案):
安装MySQL扩展: http://www.cnblogs.com/jorzy/p/8455519.html 忘记mysql的root密码解决办法: http://blog.csdn.net/weixin_40990967/article/details/80347745 http://www.cnblogs.com/sbaicl/articles/3132010.html 设置mysql5.7简单密码方法: http://blog.csdn.net/kuluzs/article/details/51924374