1.远程连接云服务器
2.创建一个存放mysql安装包的文件夹
cd /usr/local/tools
mkdir -p mysql
cd mysql
3.查看是否已经安装mysql
rpm -qa | grep mysql 或 yum list installed | grep mysql
4.如果已安装则删除 MySQL 及其依赖的包:
yum -y remove mysql-libs.x86_64
5.下载 mysql57-community-release-el7-8.noarch.rpm 的 YUM 源:
wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm
6.安装 mysql57-community-release-el7-8.noarch.rpm:
rpm -ivh mysql57-community-release-el7-8.noarch.rpm
7.安装 MySQL:
yum install mysql-server
一路 Y 下去即可
8.重置密码
vim /etc/my.cnf
在[mysqld]的段中加上一句:skip-grant-tables
例如:
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
skip-grant-tables
保存并且退出vi。
9.重新启动mysqld
启动 MySQL 服务:
service mysqld start
关闭 MySQL 服务:
service mysqld stop
重启 MySQL 服务:
service mysqld restart
查看 MySQL 的状态:
service mysqld status
登录并修改MySQL的root密码
# mysql
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 3 to server version: 3.23.56
Type ‘help;’ or ‘h’ for help. Type ‘c’ to clear the buffer.
mysql> USE mysql ;
Database changed
mysql> update mysql.user set authentication_string=password('你的新密码') where user='root';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 2 Changed: 0 Warnings: 0
mysql> flush privileges ;
Query OK, 0 rows affected (0.01 sec)
mysql> quit;
将MySQL的登录设置修改回来
# vim /etc/my.cnf
将刚才在[mysqld]的段中加上的skip-grant-tables删除
保存并且退出vim
重新启动mysqld
# service mysqld restart
三:解决远程连接mysql错误1130
远程连接Mysql服务器的数据库,错误代码是1130,ERROR 1130: Host xxx.xxx.xxx.xxx is not allowed to connect to this MySQL server
猜想是无法给远程连接的用户权限问题。
这样子操作mysql库,即可解决。
在本机登入mysql后,更改 “mysql” 数据库里的 “user” 表里的 “host” 项,从”localhost”改称'%'即可
命令:
mysql -u root -p
mysql;use mysql;
mysql;select 'host' from user where user='root';
mysql;update user set host = '%' where user ='root';
mysql;flush privileges;
mysql;select 'host' from user where user='root';
网友评论