MySQL-安装与卸载

1.查看状态

rpm -qa | grep -i mysql

查看当前服务器是否安装了mysql(有哪些与mysql相关的已安装程序)

systemctl status mysqld.service

查看mysql的运行状态

2.卸载

  1. 关闭mysql服务

systemctl stop mysqld.service

  1. yum remove 文件名

删除这几个文件

1
2
3
4
5
mysql-community-libs-5.7.36-1.el7.x86_64
mysql57-community-release-el7-9.noarch
mysql-community-client-5.7.36-1.el7.x86_64
mysql-community-common-5.7.36-1.el7.x86_64
mysql-community-server-5.7.36-1.el7.x86_64
  1. 删除mysql相关文件

find / -name mysql

  1. 查找名字是mysql的目录/文件

rm -rf 文件名/目录名

  1. 删除my.cnf

rm -rf /etc/my.cnf

3.安装

  1. 给/tmp目录足够的权限

chmod -R 777 /tmp

  1. 检查依赖
1
2
3
4
[root@iz2zeip0loevltpebhi0txz ~]# rpm -qa|grep libaio
libaio-0.3.109-13.el7.x86_64
[root@iz2zeip0loevltpebhi0txz ~]# rpm -qa|grep net-tools
net-tools-2.0-0.17.20131004git.el7.x86_64
  1. 将安装程序拷贝到/opt目录下

  2. 安装

rpm -ivh 文件名

1
2
3
4
5
6
mysql-community-common-8.0.28-1.el7.x86_64
mysql-community-client-plugins-8.0.28-1.el7.x86_64
mysql-community-libs-8.0.28-1.el7.x86_64
mysql-community-client-8.0.28-1.el7.x86_64
mysql-community-icu-data-files-8.0.28-1.el7.x86_64
mysql-community-server-8.0.28-1.el7.x86_64
  1. 查看版本

mysql --version

4. 初始化

  1. 服务初始化

mysqld --initialize --user=mysql

  1. 查看密码

cat /var/log/mysqld.log

  1. 启动mysql

systemctl start mysqld

  1. 是否自启动

systemctl list-unit-files|grep mysqld.service

enable就是开机自启动

  1. 初始登录,使用初始密码

mysql -u root -p

  1. 修改初始化密码

alter user 'root'@'localhost' identified by '新密码';(其他地方不用改)

5.远程连接

  1. 防火墙开放3306端口
  2. mysql数据库授权任何IP地址的主机都可以远程连接mysql数据库
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
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 host,user from user;;
+-----------+------------------+
| host | user |
+-----------+------------------+
| localhost | mysql.infoschema |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root | //只有localhost本机才可以连接数据库
+-----------+------------------+
4 rows in set (0.00 sec)
mysql> update user set host = '%' where user = 'root';//任何主机都可以远程连接
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> select host,user from user;;
+-----------+------------------+
| host | user |
+-----------+------------------+
| % | root |
| localhost | mysql.infoschema |
| localhost | mysql.session |
| localhost | mysql.sys |
+-----------+------------------+
4 rows in set (0.00 sec)
mysql> flush privileges;//更新
Query OK, 0 rows affected (0.01 sec)
mysql> alter user 'root'@'%' identified with mysql_native_password by '196131';
Query OK, 0 rows affected (0.01 sec)

MySQL-安装与卸载
https://vickkkyz.fun/2022/03/24/计算机/mysql/安装和卸载/
作者
Vickkkyz
发布于
2022年3月24日
许可协议