系列文章
提示:linux安装musql
1、上传jar包
https://downloads.mysql.com/archives/community/ mysql下载地址
2、解压
tar -xf mysql-8.0.28-1.el8.x86_64.rpm-bundle.tar
3、安装
rpm -ivh mysql-community-client-plugins-8.0.28-1.el8.x86_64.rpm
rpm -ivh mysql-community-common-8.0.28-1.el8.x86_64.rpm
rpm -ivh mysql-community-icu-data-files-8.0.28-1.el8.x86_64.rpm
rpm -ivh mysql-community-libs-8.0.28-1.el8.x86_64.rpm
rpm -ivh mysql-community-client-8.0.28-1.el8.x86_64.rpm
rpm -ivh mysql-community-server-8.0.28-1.el8.x86_64.rpms
4、查看数据库服务状态 | 修改默认无密码登录
systemctl status mysqld.service
cd /etc 进入配置目录
vim my.cnf 编辑MySQL配置文件
vim /etc/my.cnf
添加:skip-grant-tables
保存退出 : wq
5、登录MySQL
systemctl stop mysqld.service ----停止mysql进程
systemctl start mysqld.service ----重新运行mysql服务
mysql -u root -p 回车后提示输入密码,直接回车无密码登录
6、修改密码规则
set global validate_password.length=6; 修改密码长度
set global validate_password.policy=LOW; 修改密码等级
mysql> SHOW VARIABLES LIKE 'validate_password%'; ---查看密码规则是否已经修改(如下 6、low就是需改成功了)
+--------------------------------------+-------+
| Variable_name | Value |
+--------------------------------------+-------+
| validate_password.check_user_name | ON |
| validate_password.dictionary_file | |
| validate_password.length | 6 |
| validate_password.mixed_case_count | 1 |
| validate_password.number_count | 1 |
| validate_password.policy | LOW |
| validate_password.special_char_count | 1 |
+--------------------------------------+-------+
7、创建远程访问的账户 & 将root密码修改
flush privileges; ----刷新权限
CREATE USER 'qlx'@'%' IDENTIFIED BY '123456'; -----创建远程访问的用户
GRANT ALL PRIVILEGES ON *.* TO 'qlx'@'%'; ----- 将全部权限给予qlx用户
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456'; ---- 修改root用户密码为123456
回车出现 Query OK, 0 rows affected (0.01 sec) 表示修改成功
8、退出登录、再使用新密码登录验证步骤7修改的密码是否成功
mysql> exit ---退出登录
Bye
[root@localhost etc]# mysql -u root -p
Enter password: 此处输入新修改的密码123456
mysql> --- 代表登录成功
9、修改root用户的远程访问权限
mysql> use mysql --- 切换到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> update user set host = '%' where user = 'root'; -----修改root用户的远程访问权限
Query OK, 1 row affected (0.00 sec) -----出现Query OK代表修改成功
Rows matched: 1 Changed: 1 Warnings: 0
mysql> flush privileges; --- 刷新权限
Query OK, 0 rows affected (0.00 sec)
10、开机当前 Linux 对外开放的端口号
firewall-cmd --query-port=3306/tcp ---查看3306端口号是否已经开启
firewall-cmd --zone=public --add-port=3306/tcp --permanent ---开启3306端口号
firewall-cmd --reload ---刷新(重新加载端口号)
firewall-cmd --query-port=3306/tcp ---查看3306端口号是否已经开启
11、防火墙配置
vim etc/sysconfig/iptables-config -----编辑防火墙配置文件
添加如下:
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
12 、取消MySQL的无密码登录
vim /etc/my.cnf 将skip-grant-tabes 注释掉,或者删除掉
停止mysql
systemctl stop mysqld.service
启动mysql
systemctl start mysqld.service