【无标题】

Linux安装Mysql8.x

在线下载安装包

wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.34-1.el7.x86_64.rpm-bundle.tar

解压并安装

tar -xvf mysql-8.0.34-1.el7.x86_64.rpm-bundle.tar

在这里插入图片描述

开始安装

#mariadb的lib包和mysql的lib包冲突,删掉
rpm -qa | grep mariadb | xargs rpm -e --nodeps
#安装mysql服务
rpm -ivh mysql-community-common-8.0.34-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-plugins-8.0.34-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-8.0.34-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-8.0.34-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-compat-8.0.34-1.el7.x86_64.rpm
rpm -ivh mysql-community-icu-data-files-8.0.34-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-8.0.34-1.el7.x86_64.rpm

启动mysql并配置

#systemctl start mysqld   启动mysql数据库
[root@tidbserver mysql]# systemctl start mysqld
#grep 'temporary password' /var/log/mysqld.log  查看临时密码
[root@tidbserver mysql]# grep 'temporary password' /var/log/mysqld.log
2023-09-08T06:52:53.546042Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: JpsG?Vgfq8G7
#mysql_secure_installation  安全向导
[root@tidbserver mysql]# mysql_secure_installation
 
Securing the MySQL server deployment.
 
Enter password for user root:  #输入已获取的root用户初始临时密码
 
The existing password for the user account root has expired. Please set a new password.
 
New password:          #设置mysql root用户新密码
 
Re-enter new password: #确认密码
 
VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?
 
Press y|Y for Yes, any other key for No: no #是否安装组件 这个是校验密码强度的,建议安装 Y ;如果没有略过 
Using existing password for root.
Change the password for root ? ((Press y|Y for Yes, any other key for No) : n #是否修改root密码 刚改了 就不用了 n
 
 ... skipping.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
 
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y ##输入Y删除MySQL默认的匿名用户。
Success.
 
 
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.
 
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y #输入Y禁止root远程登录。
Success.
 
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
 
 
Remove test database and access to it? (Press y|Y for Yes, any other key for No) :  #输入Y删除test库以及对test库的访问权限。当然也可以留着
 
 ... skipping.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
 
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y #输入Y重新加载授权表。
Success.
 
All done! 

创建远程连接用户

建议使用非root账号远程登录MySQL数据库

mysql -uroot -p
输入刚刚配置安全时设置的密码
 
#创建数据库用户testmy,并授予远程连接权限。
create user 'testmy'@'%' identified by 'testmy123'; 
 
#为testmy用户授权数据库所有权限。
grant all privileges on *.* to 'testmy'@'%'; 
 
#创建新用户会默认使用新的 caching_sha2_password,客户端不支持新的加密方式,修改
ALTER USER 'testmy'@'%' IDENTIFIED WITH mysql_native_password BY 'testmy123';
 
#刷新权限。
flush privileges;

root用户密码修改

-- 登录到MySQL服务器
mysql -u root -p
 
-- 输入当前root用户的密码进行身份验证
 
-- 切换到mysql数据库
USE mysql;
 
-- 查看所有用户及其对应的主机信息
SELECT user, host FROM user;
 
-- 更新root用户的密码为"new_password"(将"new_password"替换成你想要设置的新密码)
ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'new_password';
 
-- 如果需要同时支持旧版本的加密算法,则添加以下命令
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'P@ssw0rd';
 
-- 刷新系统权限表
FLUSH PRIVILEGES;
 
-- 退出MySQL客户端
EXIT;

  • 12
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值