centos7 安装 mysql

常用命令

1
2
3
4
5
6
// 启动
> service mysqld start
// 关闭
> service mysqld stop
// 重启
> service mysqld restart

安装之前先安装基本环境:

1
> yum install -y perl perl-Module-Build net-tools autoconf libaio numactl-libs

安装 mysql

1
2
3
4
# 下载mysql源安装包
> wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
# 安装mysql源
> yum localinstall mysql57-community-release-el7-8.noarch.rpm

检查mysql源是否安装成功

1
> yum repolist enabled | grep "mysql.*-community.*"

安装mysql

1
> yum install mysql-community-server

启动 mysql

1
> systemctl start mysqld

查看 mysql 状态

1
> systemctl status mysqld

开机启动

1
2
> systemctl enable mysqld
> systemctl daemon-reload

修改root本地密码

1
2
3
4
5
// 查看初始密码
> grep 'temporary password' /var/log/mysqld.log

// 设置新密码
> set password for 'root'@'localhost'=password('MyNewPass4!');

添加远程账户

1
> GRANT ALL PRIVILEGES ON *.* TO 'testName'@'%' IDENTIFIED BY 'passWord' WITH GRANT OPTION;

配置 UTF-8 编码

1
2
3
4
5
6
> vim /etc/my.cnf

// 添加编码
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'