linux RedHat7.4 安装mysql8.0(rpm方式安装)

目录

 

1.下载软件包:

2.安装

3.初始化MySQL:

4.启动Mysql:

5.查看 MySQL 运行状态:

6.验证:

7.修改初始密码

方式一:

方式二:

8.授权远程访问

9.mysql常用语句

10.重要目录(默认安装目录)

11.重要命令


1.下载软件包:

wget https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm

2.使用yum在线安装

rpm -ivh mysql80-community-release-el7-1.noarch.rpm
yum install mysql-server

安装过程中会需要提示下载依赖,按y确认下载即可:

3.初始化MySQL:

mysqld --initialize

4.启动MySQL:

# RedHat6 下启动命令
service mysqld start

# RedHat7 下启动命令
systemctl start mysqld.service


# 设置开机启动
systemctl enable mysqld
systemctl daemon-reload

5.查看 MySQL 运行状态:

# RedHat6 下查看mysql状态
service mysqld status

# RedHat7 下查看mysql状态
systemctl status mysqld.service

6.验证:

mysqladmin --version

# 执行上述命令后显示如下信息:
# mysqladmin  Ver 8.0.18 for Linux on x86_64 (MySQL Community Server - GPL)

7.修改初始密码

# MySQL 5.7 调整密码验证规则:
mysql> set global validate_password_policy=0;
mysql> set global validate_password_length=1;

# MySQL 8.0 调整密码验证规则:
mysql> set global validate_password.policy=0;
mysql> set global validate_password.length=1;

# MySQL5.7 和 MySQL8.0 密码验证插件种变量名不一样。(_password_policy 和 _password.policy )
# 用命令查看 validate_password 密码验证插件是否安装。
mysql> SHOW VARIABLES LIKE ‘validate_password%’;

方式一:

1)刚刚启动成功之后,  用命令查看默认密码并且登录  
     查看:cat /var/log/mysqld.log | grep password
     登陆:mysql -u root -p     # 然后输入密码 

2)修改密码
    set global validate_password.policy=0;
    set global validate_password.length=1;
    ALTER USER "root"@"localhost" IDENTIFIED  BY "1234";  ## 新密码为1234

3) exit    退出
     
         mysql -u root -p    ## 然后输入密码即可登录

方式二:

1)停止mysql

systemctl stop mysqld.service

2)编辑配置文件

vi /etc/my.cnf

# 尾部加上:
skip-grant-tables

2)重启mysql服务,修改密码(密码置空)

[root@localhost ~]# systemctl start mysqld.service

[root@localhost ~]# mysql -u root -p
Enter password: ##直接回车
mysql> use mysql;                                                      ## 进入mysql表
mysql> update user set authentication_string='' where user='root';     ## 将密码设置为空(必须在mysql库设置)
mysql> exit

[root@localhost ~]# vi /etc/my.cnf                ## 尾部去掉 skip-grant-tables
[root@localhost ~]# systemctl restart mysqld      ## 重启mysql
[root@localhost ~]# mysql -u root -p
Enter password: ##直接回车
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码'; 
mysql> flush privileges;    ##刷新权限     
mysql> exit   ## mysql -u root -p    然后输入新密码即可登录

8.授权远程访问

-- 创建所有用户都可以访问的用户规则,在mysql8.0中 授权语句已经更换,使用之前的sql语句授权会报错;
create user 'root'@'%' identified WITH mysql_native_password by 'Root@123'; 
-- 对这个用户规则进行授权
grant all privileges on *.* to 'root'@'%'; 
flush privileges; -- 刷新权限 

9.mysql常用配置
 

# 配置默认编码为utf8
# 修改/etc/my.cnf配置文件,在[mysqld]下添加编码配置,如下所示:

[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
# mysql -u root -p ##登陆
use mysql;
show databases; 
show tables;

-- 查看用户是否允许远程登录 localhost 仅本地  % 可以远程登录
select host,user, authentication_string, plugin from user; \G; -- \G表示格式化显示 
   
-- 修改root用户可远程登录. 
update user set host= '%' where user = 'root'; 

-- 修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '你的密码';
ALTER USER "root"@"%" IDENTIFIED  BY "你的密码";

-- 修改为旧的密码认证方式.
use mysql;
alter USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '你的密码';
flush privileges; #刷新权限

-- 修改加密规则  mysql5.7.6之后就修改了加密规则,所以需要更改加密方式。
update user set plugin='mysql_native_password' where user ='root';

-- 创建所有用户都可以访问的用户规则,在mysql8.0中 授权语句已经更换,使用之前的sql语句授权会报错;
create user 'root'@'%' identified WITH mysql_native_password by 'Root@123'; 
-- 对这个用户规则进行授权
grant all privileges on *.* to 'root'@'%'; 
flush privileges; #刷新权限

10.重要目录(默认安装目录)

/etc/my.cnf                # 配置文件

/var/lib/mysql                #数据库目录
/usr/share/mysql           # 配置文件目录
/usr/bin                         #相关命令目录
/var/log/mysqld.log # log-error         # 日志文件
/var/run/mysqld/mysqld.pid          # pid-file
/etc/init.d/mysql       #启动脚本
————————————————

11.重要命令

# 查看运行进程
ps -ef | grep mysqld

# 查看端口
netstat -tulpn |grep mysqld


## 服务操作:
# 启动服务
systemctl start mysqld

# 重启服务
systemctl restart mysqld

# 加入开机启动
systemctl enable mysqld;

# 停止运行服务
systemctl stop  mysqld ;

# 加入开机禁用
systemctl disable  mysqld;

# 查看状态
systemctl status mysqld;

# 查看httpd的开机启动状态列表
systemctl list-unit-files;
发布了18 篇原创文章 · 获赞 16 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/liangpingguo/article/details/103924003
今日推荐