参考mysql 官方指导文档,https://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/
wget -i -c https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm
```bash
[root@ahdyqrh0apjy8y2w software]# wget -c -i https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm
--2021-08-16 15:12:27-- https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm
Resolving repo.mysql.com (repo.mysql.com)... 104.85.245.54
Connecting to repo.mysql.com (repo.mysql.com)|104.85.245.54|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 26024 (25K) [application/x-redhat-package-manager]
Saving to: ‘mysql80-community-release-el7-3.noarch.rpm’
mysql80-community-release-el7-3.noarch.rpm 100%[=======================================================================================================>] 25.41K 146KB/s in 0.2s
2021-08-16 15:12:28 (146 KB/s) - ‘mysql80-community-release-el7-3.noarch.rpm’ saved [26024/26024]
Incomplete or invalid multibyte sequence encountered
--2021-08-16 15:12:28-- https://repo.mysql.com//%ED%AB%EE%DB%03
Reusing existing connection to repo.mysql.com:443.
HTTP request sent, awaiting response... 400 Bad Request
2021-08-16 15:12:28 ERROR 400: Bad Request.
--2021-08-16 15:12:28-- https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm
Reusing existing connection to repo.mysql.com:443.
HTTP request sent, awaiting response... 200 OK
```
yum -y install mysql80-community-release-el7-3.noarch.rpm
[root@ahdyqrh0apjy8y2w software]# yum -y install mysql80-community-release-el7-3.noarch.rpm
Last metadata expiration check: 0:21:13 ago on Mon 16 Aug 2021 02:54:28 PM CST.
Dependencies resolved.
================================================================================================================================================================================================
Package Architecture Version Repository Size
================================================================================================================================================================================================
Installing:
mysql80-community-release noarch el7-3 @commandline 25 k
Transaction Summary
================================================================================================================================================================================================
Install 1 Package
Total size: 25 k
Installed size: 31 k
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : mysql80-community-release-el7-3.noarch 1/1
Verifying : mysql80-community-release-el7-3.noarch 1/1
Installed:
mysql80-community-release-el7-3.noarch
Complete!
[root@ahdyqrh0apjy8y2w software]# ll
total 28
-rw-r--r-- 1 root root 26024 Apr 25 2019 mysql80-community-release-el7-3.noarch.rpm
[root@ahdyqrh0apjy8y2w software]#
yum module disable mysql
yum -y install mysql-community-server
[root@ahdyqrh0apjy8y2w software]# yum -y install mysql-community-server
MySQL 8.0 Community Server 783 kB/s | 2.0 MB 00:02
MySQL Connectors Community 61 kB/s | 121 kB 00:01
MySQL Tools Community 280 kB/s | 722 kB 00:02
No match for argument: mysql-community-server
Error: Unable to find a match: mysql-community-server
[root@ahdyqrh0apjy8y2w software]#
systemctl start mysqld
systemctl status mysqld
需修改初始化密码才能使用mysql数据库
修改密码规则如下:密码中必须包含大小写字母数字及符号——提供参照密码‘tyzZ001!’
‘root’@‘localhost’ 创建了 一个超级用户帐户。超级用户的密码已设置并存储在错误日志文件中。要显示它,请使用以下命令:
grep “password” /var/log/mysqld.log
[root@ahdyqrh0apjy8y2w ~]# grep "password" /var/log/mysqld.log
2021-08-16T07:44:29.420776Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: )+rfsdrf8FSL
通过使用生成的临时密码登录并为超级用户帐户设置自定义密码,尽快更改 root 密码:
mysql -uroot -p
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
yum -y remove mysql80-community-release-el7-3.noarch.rpm
[root@localhost ~]# systemctl start mysqld.service #开启服务
[root@localhost ~]# systemctl stop mysqld.service #关闭服务
[root@localhost ~]# systemctl status mysqld.service #查看服务状态
[root@localhost ~]# mysql -u root -p #进入mysql命令窗口
mysql> show databases; #查看所有数据库
mysql> use 数据库名; #使用该数据进行编辑
mysql> show tables; #查看某数据库所有表
//查看mysql服务状态
[root@mytestlnx02 ~]# ps -ef | grep -i mysql
root 22972 1 0 14:18 pts/0 00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock --pid-file=/var/run/mysqld/mysqld.pid --basedir=/usr --user=mysql
mysql 23166 22972 0 14:18 pts/0 00:00:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/mysql/plugin --user=mysql --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock
root 23237 21825 0 14:22 pts/0 00:00:00 grep -i mysql
//关闭服务
[root@mytestlnx02 ~]# service mysql stop
[root@mytestlnx02 ~]#
在配置文件中,末尾增加1行代码
skip-grant-tables
作用是登录mysql的时候跳过密码验证
然后启动mysql服务,并进入mysql
[root@mytestlnx02 ~]# service mysqld start
[root@mytestlnx02 ~]#
[root@mytestlnx02 ~]# mysql -u root
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
连接mysql这个数据库,修改用户密码,将密码先设置为空
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> update user set authentication_string='' where user='root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
先将之前加在配置文件里面的2句代码注释或删除掉,然后重启mysql服务,就可以使用刚刚设置的密码登录了。
[root@mytestlnx02 ~]# service mysql start
[root@mytestlnx02 ~]#
[root@mytestlnx02 ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
# 已密码方式登录,测试密码为空,可以直接登录成功
mysql -u root
# 修改密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '你的密码';
首先参考mysql卸载
其次用yum命令卸载:yum remove mysql-community-server
解决办法,查看日志,杀掉mysql进程,查看杀进程的命令
查看端口占用情况:
# 查询端口号占用情况
netstat -anp|grep 3306
# 根据进程查看占用情况
ps -aux|grep mysql
# 删除mysql 进程
kill -9 pid
在装有MySQL的机器上登录MySQL mysql -u root -p密码
执行use mysql;
执行update user set host = ‘%’ where user = ‘root’;这一句执行完可能会报错,不用管它。
执行FLUSH PRIVILEGES;