1.首先下载mysql-community对应的centos7(既rhel7)RPM包,
地址为: https://dev.mysql.com/downloads/repo/yum/
2.然后是会用yum安装上述rpm包
sudo yum install -y mysql57-community-release-el7-11.noarch.rpm
3.使用yum安装mysql-community-server
sudo yum install -y mysql-community-server
3.1 安装mysql-community-server失败,缺少依赖mariadb
3.2 安装依赖 mariadb
3.3重新安装mysql-community-server : sudo yum install -y mysql-community-server
4.启动mysql-server服务
sudo systemctl start mysqld
5.第一次启动时会在/var/log/mysqld.log生成一个随机的root密码,使用该密码登录mysql并设置root密码
grep “password” /var/log/mysqld.log
mysql -u root -p
#进入mysql,设置root密码
mysql> set password=‘Lee*123456’;
5.1关于mysql设置密码策略问题 https://blog.csdn.net/hello_world_qwp/article/details/79551789
6.修改mysql默认的字符编码为utf8,编辑/etc/my.cnf,在 [mysqld] 标签下添加如下内容:
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
init_connect=‘SET collation_connection = utf8_unicode_ci’
init_connect=‘SET NAMES utf8’
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake
重启mysqld服务
sudo systemctl restart mysqld
使用show variables like “%character%”;show variables like “%collation%”;命令查看mysql默认字符编码:
mysql -u root -p
show variables like “%character%”;show variables like “%collation%”;
mysql在centos安装完成。
- 创建数据库使用如下的命令
create database Leedb default character set utf8 collate utf8_bin;
grant all on Leedb.* to ‘lee’@’%’ identified with mysql_native_password by ‘Lee*123456’; --使远程能够生效
flush privileges; --刷新权限
使用命令 # service mysqld status 或者 # service mysql status 命令来查看mysql 的启动状态
启动服务
service mysql start #启动服务
service mysql stop #关闭服务
service restart stop #重启服务