欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

centos7安装mysql5.7

程序员文章站 2024-03-25 17:07:28
...

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

4. 启动mysql-server服务

sudo systemctl start mysqld

5.第一次启动时会在/var/log/mysql.log生成一个随机的root密码,使用该密码登录mysql并设置root密码

centos7安装mysql5.7

grep "password" /var/log/mysql.log
mysql -u root -p

#进入mysql,设置root密码
mysql> set password='aaa@qq.com';

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%";

centos7安装mysql5.7

mysql5.7在centos安装完成。

7. 创建数据库使用如下的命令

create database mydb default character set utf8 collate utf8_bin;
grant all on mydb.* to 'mydb'@'%' identified by 'aaa@qq.com';
flush privileges;
centos7安装mysql5.7

相关标签: linux mysql