CentOS7 安装mysql以及登录

准备工作:已下载mysql安装包

1. 检查是否安装Centos7自带的数据库mariadb

[root@sam03 ~]# rpm -qa | grep mariadb

image

2. 卸载mariadb

[root@sam03 ~]# rpm -e mariadb-libs-5.5.64-1.el7.x86_64 --nodeps

image

3. 解压mysql安装包

[root@sam03 opt]# tar -xvf mysql-5.7.28-1.el7.x86_64.rpm-bundle.tar

3.1 解压后的文件

image

4. 安装(按以下步骤顺序进行)

rpm -ivh mysql-community-common-5.7.28-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.28-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.28-1.el7.x86_64.rpm
yum install -y net-tools
rpm -ivh mysql-community-server-5.7.28-1.el7.x86_64.rpm

5. 开启mysql服务

5.1 查看mysql进程状态

[root@sam03 opt]# systemctl status mysqld

image


显示inactive状态

5.2 开启mysql进程

[root@sam03 opt]# systemctl start mysqld

5.3 再次查看mysql进程,显示active状态

image

6. 登录mysql

第一次开启mysql服务时,会自动生成一个登录密码

6.1 查看初始密码

[root@sam03 opt]# grep password /var/log/mysqld.log

image

6.2 登录mysql

[root@sam03 opt]# mysql -u root -p

image

7. 修改mysql登录密码

7.1 修改安全等级

show variables like '%validate_password%';					# 查看密码策略
set global validate_password_policy=LOW;						# 修改密码策略等级为LOW
set global validate_password_length=3;							# 密码的最小长度
set global validate_password_mixed_case_count=0;	  # 设置密码中至少要包含0个大写字母和小写字母
set global validate_password_number_count=0;			 	# 设置密码中至少要包含0个数字
set global validate_password_special_char_count=0;	# 设置密码中至少要包含0个特殊字符

image

7.2 修改密码

mysql> alter user root@localhost identified by '123456';

8. mysql远程授权

mysql> grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
posted @ 2022-02-26 14:40  递茶大户  阅读(852)  评论(0编辑  收藏  举报