centos8使用yum命令按照mysql

前言

参考mysql 官方指导文档,https://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/

1. 下载rpm,从mysql官方库(https://dev.mysql.com/downloads/repo/yum/)找到rpm下载地址链接

在这里插入图片描述
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
```

2.yum命令安装下载的rmp

 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]# 

3. 禁用默认的mysql模块

yum module disable mysql

4. 安装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]# 

5. 启动mysql服务器

systemctl start mysqld

6. 检查mysql的状态

systemctl status mysqld

7. 查看超级用户的密码并修改

需修改初始化密码才能使用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!';

8.因安装了Yum Repository,每次使用yum操作时都会自动更新,所以可以选择它卸载掉:

yum -y remove mysql80-community-release-el7-3.noarch.rpm

9.mysql 常用命令

[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; #查看某数据库所有表

10.linux下mysql密码忘记解决办法

10.1 检查mysql服务是否启动,如果启动,关闭mysql服务

//查看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 ~]#

10.2 my.cnf配置文件的位置,一般在/etc/my.cnf,有些版本在/etc/mysql/my.cnf

在配置文件中,末尾增加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>

10.3 修改密码

连接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

10.4 重启mysql服务

先将之前加在配置文件里面的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.

10.5 登录mysql并修改密码

# 已密码方式登录,测试密码为空,可以直接登录成功
mysql -u root 
# 修改密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '你的密码';

11、mysql 卸载

首先参考mysql卸载
其次用yum命令卸载:yum remove mysql-community-server

12、常见问题

12.1、Job for mysqld.service failed because the control process exited with error code.

解决办法,查看日志,杀掉mysql进程,查看杀进程的命令
查看端口占用情况:

# 查询端口号占用情况
netstat -anp|grep 3306
# 根据进程查看占用情况
ps -aux|grep mysql
# 删除mysql 进程
kill -9 pid

12.2 Host is not allowed to connect to this MySQL server解决方法

在装有MySQL的机器上登录MySQL mysql -u root -p密码
执行use mysql;
执行update user set host = ‘%’ where user = ‘root’;这一句执行完可能会报错,不用管它。
执行FLUSH PRIVILEGES;

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值