问题:centos安装MySQL
解决:
1、下载并安装MySQL官方的 Yum Repository
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql-community-server
如遇到 mysql-community-client-5.7.39-1.el7.x86_64.rpm 的公钥尚未安装
则执行命令 rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
然后再执行 yum -y install mysql-community-server
2、MySQL数据库设置
启动:systemctl start mysqld.service
# 停止:systemctl stop mysqld.service
# 开机启动:systemctl enable mysqld.service
查看状态:systemctl status mysqld.service
在日志文件中查找密码:grep "password" /var/log/mysqld.log
进入数据库:mysql -uroot -p
修改MySQL密码:mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';
3、开启mysql远程访问
mysql> grant all privileges on *.* to 'root'@'192.168.0.1' identified by 'password' with grant option;
mysql> flush privileges;
4、更改mysql语言
打开配置文件:vim /etc/my.cnf
加入以下几行代码:
[client]
default-character-set=utf8default-storage-engine=INNODB
character-set-server=utf8
collation-server=utf8_general_ci
5、重启MySQL
6、查看字符状态
登录MySQL查看状态:
mysql> status;
或
mysql> show variables like 'chara%';