【centos下的mysql配置安装 (yum) 学习笔记】
1.配置yum源
#下载yum源安装包
wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
#安装mysql源
yum localinstall mysql57-community-release-el7-8.noarch.rpm
#检查是否安装成功
yum repolist enabled | grep "mysql.*-community.*"
#查看是否已经安装 rpm -qa | grep mysql 或 yum list installed | grep mysql
2.安装mysql
yum install mysql-community-server
3.启动mysql
systemctl start mysqld
查看mysql 启动状态
systemctl status mysqld
4.开机启动
systemctl enable mysqld
systemctl daemon-reload
5.修改rooot本地登入密码
mysql安装完成之后,在/var/log/mysqld.log文件中给root生成了一个默认密码。通过下面的方式找到root默认密码,然后登录mysql进行修改:
grep 'password' /var/log/mysqld.log
mysql -uroot -p
密码
更改密码:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
或:
set password for 'root'@'localhost'=password('MyNewPass4!');
如要更改简单密码 先更改全局参数
ERROR1819 (HY000): Your password does NOT satisfy the CURRENT policyrequirements
mysql> set global validate_password_policy=0;
mysql> set global validate_password_length=1;
查看密码策略的相关信息:
show variables like '%password%';
6.添加远程登入
默认只允许root帐户在本地登录,如果要在其它机器上连接mysql,必须修改root允许远程连接,或者添加一个允许远程连接的帐户,为了安全起见,我添加一个新的帐户:
mysql> GRANT ALL PRIVILEGES ON *.* TO 'yangxin'@'%' IDENTIFIED BY 'Yangxin0917!' WITH GRANT OPTION;
7.配置编码utf-8
修改/etc/my.cnf配置文件,在[mysqld]下添加编码配置,如下所示:
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
8.默认配置文件路径
配置文件:/etc/my.cnf
日志文件:/var/log//var/log/mysqld.log
服务启动脚本:/usr/lib/systemd/system/mysqld.service
socket文件:/var/run/mysqld/mysqld.pid