yum 方式安装mysql 5.7
cd /usr/local/src
wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
rpm -ivh mysql57-community-release-el7-11.noarch.rpm
yum -y remove mariadb*
yum install mysql-community-server -y
systemctl start mysqld
tail -100 /var/log/mysqld.log
grep ‘temporary password‘ /var/log/mysqld.log
##提取出初始root密码,假如密码是S*_gPaVTL1w4
修改初始root密码
mysql -hlocalhost -uroot -p‘S*_gPaVTL1w4‘
mysql> ALTER USER ‘root‘@‘localhost‘ IDENTIFIED BY ‘MyNewPass4!‘;
#或者
mysql> set password for ‘root‘@‘localhost‘=password(‘MyNewPass4!‘);
以后通过 update set 语句修改密码
mysql> use mysql;
mysql> update user set password=PASSWORD(‘MyNewPass5!‘) where user=‘root‘;
mysql> flush privileges;
添加远程登录用户
默认只允许root帐户在本地登录,如果要在其它机器上连接mysql,必须添加一个允许远程连接的帐户。或者修改 root 为允许远程连接(不推荐)
添加一个允许远程连接的帐户
mysql> GRANT ALL PRIVILEGES ON *.* TO ‘zhangsan‘@‘%‘ IDENTIFIED BY ‘Zhangsan2018!‘ WITH GRANT OPTION;
修改 root 为允许远程连接(不推荐)
mysql> use mysql;
mysql> UPDATE user SET Host=‘%‘ WHERE User=‘root‘;
mysql> flush privileges;
设置默认编码为 utf8
mysql 安装后默认不支持中文,需要修改编码。
修改 /etc/my.cnf 配置文件,在相关节点(没有则自行添加)下添加编码配置,如下:
[mysqld]
character-set-server=utf8
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
重启mysql服务,查询编码。可以看到已经改过来了
shell> systemctl restart mysqld
shell> mysql -uroot -p
mysql> show variables like ‘character%‘;
默认配置文件路径:
配置文件:/etc/my.cnf
日志文件:/var/log/mysqld.log
服务启动脚本:/usr/lib/systemd/system/mysqld.service
socket文件:/var/run/mysqld/mysqld.pid