安装 MySQL
查看系统版本(输出结果会看到 CentOS Linux 7 (Core) )
cat /etc/os-release
获取 mysql yum repository 链接:https://dev.mysql.com/downloads/repo/yum/
cd /usr/local/src/
wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
安装源:
yum -y install mysql80-community-release-el7-3.noarch.rpm
以下为检测安装源及输出信息:
yum repolist enabled | grep "mysql.*-community.*"
mysql-connectors-community/x86_64 MySQL Connectors Community 131
mysql-tools-community/x86_64 MySQL Tools Community 100
mysql80-community/x86_64 MySQL 8.0 Community Server 145
安装 MySQL
yum -y install mysql-community-server
安装完成将显示如下信息:
Installed:
mysql-community-libs.x86_64 0:8.0.18-1.el7 mysql-community-libs-compat.x86_64 0:8.0.18-1.el7
mysql-community-server.x86_64 0:8.0.18-1.el7
Dependency Installed:
libaio.x86_64 0:0.3.109-13.el7 mysql-community-client.x86_64 0:8.0.18-1.el7
mysql-community-common.x86_64 0:8.0.18-1.el7
Replaced:
mariadb-libs.x86_64 1:5.5.60-1.el7_5
Complete!
安装完成
安装成功后
启动 mysql 等操作
service mysqld start
service mysqld status
service mysqld stop
service mysqld restart
systemctl start mysqld.service
systemctl status mysqld.service
systemctl stop mysqld.service
systemctl restart mysqld.service
获取密码:
grep "password" /var/log/mysqld.log
... password is generated for root@localhost: %isC&hkru0v0
登录:
mysql -uroot -p
修改密码:
alter user root@localhost identified by 'password';
创建用户:
use mysql;
create user 'root'@'%' identified by 'password';
grant all privileges on *.* to 'root'@'%';
flush privileges;
通过Navicat等工具连接失败,更改加密规则
# 修改加密规则
alter user 'root'@'%' identified by 'password' password expire never;
# 更新密码
alter user 'root'@'%' identified with mysql_native_password by 'password';
修改配置
查看使用的配置文件(当前默认无)
ps aux|grep mysql|grep 'my.cnf'
MySQL 默认会搜寻 my.cnf 的目录,顺序排前的优先,
查找 my.cnf ,只存在 /etc/my.cnf
mysql --help|grep 'my.cnf'
order of preference, my.cnf, $MYSQL_TCP_PORT,
/etc/my.cnf /etc/mysql/my.cnf /usr/etc/my.cnf ~/.my.cnf
查看字符集配置
show variables where Variable_name like 'character%' or Variable_name like 'collation%';
在 /etc/my.cnf 添加如下内容,完成后重启 MySQL
[client]
default-character-set = utf8mb4
[mysql]
default-character-set = utf8mb4
[mysqld]
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect='SET NAMES utf8mb4'