一、准备
其实rpm安装是比较省事儿的,直接在官网上下载mysql的rpm版本,下载地址如下:https://dev.mysql.com/downloads/mysql/,如下图所示选择对应的版本
二、.卸载
1.检查安装过的mysql rpm文件
rpm -qa | grep -i mysql2.卸载安装过的mysql rpm文件
rpm -ev mysql-* --nodeps
或者使用 yum remove mysql-*3.查找mysql相关的文件以及文件夹
find / -name mysql4.删除相关的文件或者文件夹
rm -rf 文件/文件夹
5.查看是否安装了Mariadb
rpm -qa | grep mariadb6.如果安装了 Mariadb,卸载掉
rpm -e mariadb-* --nodeps
7.安装Development Tools
yum groupinstall Development Libraries yum groupinstall Development Tools yum install ncurses-devel zlib-devel texinfo gtk+-devel gtk2-devel qt-devel tcl-devel tk-devel libX11-devel kernel-headers kernel-devel
三、安装rpm包
解压tar安装包:
tar -xvf /usr/local/mysql-5.7.18-1.el6.x86_64.rpm-bundle.tar
按照如下顺序安装rpm包
# rpm -ivh mysql-community-common-5.7.17-1.el7.x86_64.rpm # rpm -ivh mysql-community-libs-5.7.17-1.el7.x86_64.rpm # rpm -ivh mysql-community-client-5.7.17-1.el7.x86_64.rpm # rpm -ivh mysql-community-server-5.7.17-1.el7.x86_64.rpm # rpm -ivh mysql-community-devel-5.7.17-1.el7.x86_64.rpm四、启动、停止mysql
# service mysqld start //启动 # service mysqld stop //停止 # service mysqld status //查看当前mysql服务的状态五、查看初始的随机密码
# cat /var/log/mysqld.log | more结果如下:
初始随机密码为:N3s(o=(h=w0W
六、修改密码已经授权远程
1.使用如下命令进入mysql,并输入初始随机密码登陆成功:
[root@bogon ~]# service mysqld start [root@bogon ~]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. mysql> grant all privileges on *.* to 'root'@'%' identified by 'Pwd@123456'; Your MySQL connection id is 141 Server version: 5.7.18 MySQL Community Server (GPL) Copyright (c) 2000, 2017, 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.
2.设置密码:
mysql> set password='Pwd@123456';3.授权远程访问:
mysql> grant all privileges on *.* to 'root'@'%' identified by 'Pwd@123456';
1.改表发
可能是你的帐号不允许从远程登陆,只能在localhost。这个时候只要在localhost的那台电脑,登入mysql后,更改 "mysql" 数据库里的 "user" 表里的 "host" 项,从"localhost"改称"%" mysql -u root -p123 mysql>use mysql; mysql>update user set host = '%' where user = 'root';2.进入mysql 授予表 数据库 权限
修改二代码 授权法。例如,你想 Ufinity 使用mypassword从任何主机连接到mysql服务器的话。 GRANT ALL PRIVILEGES ON *.* TOIDENTIFIED BY 'mypassword' WITH GRANT OPTION; 要及时生效 : FLUSH PRIVILEGES 如果你想允许用户kevin从ip为192.168.1.139的主机连接到mysql服务器,并使用mypassword作为密码 GRANT ALL PRIVILEGES ON *.* TOIDENTIFIED BY 'mypassword' WITH GRANT OPTION;3.防火墙
最后方法代码 //关闭防火墙 service iptables stop
其实1,2都是为了在mysql 的 mysql数据库中的 user表 里面有这样的记录 Sql代码 select Host ,User from user where User ='root' and Host ='%'; select Host ,User from user where User ='root' and Host ='%'; +------+------+ | Host | User | +------+------+ | % | root | +------+------+ 意思是 以root 用户登陆 ,在局域网 中 所有的其他主机上都可以访问 最后实在不行 关闭防火墙。