安装 MySql
在这里插入代码片
sudo apt-get install mysql-server
初始化配置
sudo mysql_secure_installation
学习用途统一设置密码为:mysql
密码难度等级
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0
进制远程登录?
Disallow root login remotely?
删除测试数据库并访问它?
Remove test database and access to it?
现在重新加载特权表?
Reload privilege tables now?
查看服务的状态信息
systemctl status mysql.service
根用户权限进入
sudo mysql -uroot -p
GRANT ALL PRIVILEGES ON *.* TO root@localhost IDENTIFIED BY "123456";
localhost
:表示仅本地访问,改为%
就是所有主机可以链接。
123456
:为新增权限用户设置的密码,%
表示所有主机
在 https://dev.mysql.com/downloads/repo/yum/ 找到 yum 源 rpm 安装包
安装 MySQL源
# 下载
shell> wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
# 安装 mysql 源
shell> yum localinstall mysql57-community-release-el7-11.noarch.rpm
用下面的命令检查 mysql 源是否安装成功
yum repolist enabled | grep "mysql.*-community.*"
yum install -y mysql-community-server
启动MySQL服务器和MySQL的自动启动
systemctl start mysqld
systemctl enable mysqld
查看安装状态
systemctl status mysqld
重载修改过配置的文件
systemctl daemon-reload
查询临时密码
grep 'temporary password' /var/log/mysqld.log
修改密码
alter user 'root'@'localhost' IDENTIFIED BY 'root';
或者
set password for 'root'@'localhost'=password('root');
配置允许简单密码
设置密码有效程度 4 为及以上
set global validate_password_length=4;
设置密码策略最低级别
set global validate_password_policy=0;
登录
mysql -uroot -p
show databases;
show global variables like 'port';
mysql> show global variables like 'port';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port | 3306 |
+---------------+-------+
1 row in set (0.01 sec)
select host,user from mysql.user;
mysql> select host,user from mysql.user;
+-----------+------------------+
| host | user |
+-----------+------------------+
| localhost | mysql.infoschema |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
+-----------+------------------+
4 rows in set (0.00 sec)
此操作需要root用户来进行
创建数据库
:csdb
CREATE DATABASE csdb;
1、创建用户
创建用户:cs
密码:cslogin
create user cs identified by 'cslogin';
2、修改密码
3、查看用户
select user, host from mysql.user;
4、删除用户
drop user cs@'%';
将csdb数据库
的所有操作权限都授权给用户cs
,密码:cslogin
grant all privileges on csdb.* to cs@'%' identified by 'cslogin';
flush privileges;
查看用户cs,权限授予执行的命令
show grants for 'cs';
Failing package is: mysql-community-client-5.7.38-1.el7.x86_64 GPG Keys are configured as: file://
原因:MySQL GPG 密钥已过期导致
解决办法:执行一下命令,解决
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022