首页
编程随笔
Java笔记
Html/Css/Js
Android
后端笔记
服务器搭建
BUG收集
Java异常
Android异常
在线工具
Json格式化
编码/解码
Epub在线编辑
登录
发布文章
个人文章
退出登录
首页
技术教程
BUG收集
在线工具
资源下载
登录
发布文章
退出登录
搜索
当前位置:
首页
-
博客
- 正文
关闭
Centos安装mysql 5.7
更新时间:2023-06-23 23:36:01
阅读数:550
发布者:落幕
本文安装的mysql版本为5.7,需要安装mysql 8.0以上可自行换yum文件 ### 1、下载和安装mysql ```mysql yum -y install https://repo.mysql.com//mysql57-community-release-el7-11.noarch.rpm sed -i 's/gpgcheck=1/gpgcheck=0/g' /etc/yum.repos.d/mysql-community.repo yum clean all yum -y install mysql-community-server mysql-community-client ``` ### 2、配置mysql vi /etc/my.cnf 添加如下内容: ```txt [mysqld] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid character-set-server = utf8 collation-server = utf8_general_ci init_connect = "SET NAMES 'utf8'" explicit_defaults_for_timestamp=true [mysql] default-character-set = utf8 [client] default-character-set = utf8] ``` ### 3、初始化mysql登录密码 ```shell mkdir -p /opt/data/mysql mysqld --initialize --datadir=/opt/data/mysql --user=mysql cat /var/log/mysqld.log | grep "temporary password" ``` 2023-06-23T14:24:36.418927Z 1 [Note] A temporary password is generated for root@localhost: j_urk/?#t6:Q j_urk/?#t6:Q就是初始化登录mysql密码 ### 4、启动mysql ```shell # 启动mysql systemctl start mysqld # mysl开机启动 systemctl enable mysqld # 查看mysql启动状态 systemctl status mysqld ``` ### 5、修改密码 登录mysql mysql -u root -p 修改密码 ALTER USER USER() IDENTIFIED BY 'Admin2023!'; 修改成安全级别的密码,例如123456 修改密码策略 SHOW VARIABLES LIKE "validate_password%"; +--------------------------------------+-------+ | Variable_name | Value | +--------------------------------------+-------+ | validate_password_check_user_name | OFF | | validate_password_dictionary_file | | | validate_password_length | 8 | | validate_password_mixed_case_count | 1 | | validate_password_number_count | 1 | | validate_password_policy | LOW | | validate_password_special_char_count | 1 | +--------------------------------------+-------+ ```shell # 密码级别设为低 set global validate_password_policy=LOW; # 密码最小长度设置为6 set global validate_password_length = 6; #修改密码为123456 alter user 'root'@'localhost' identified by '123456'; #允许root用户能远程登录 grant all privileges on *.* to root@'%' identified by '123456'; #刷新 FLUSH PRIVILEGES; ```