关于

centos7 安装 mysql

常用命令

// 启动
> service mysqld start
// 关闭
> service mysqld stop
// 重启
> service mysqld restart

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

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

安装 mysql

# 下载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源是否安装成功

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

安装mysql

> yum install mysql-community-server

启动 mysql

> systemctl start mysqld

查看 mysql 状态

> systemctl status mysqld

开机启动

> systemctl enable mysqld
> systemctl daemon-reload

修改root本地密码

// 查看初始密码
> grep 'temporary password' /var/log/mysqld.log

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

添加远程账户

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

配置 UTF-8 编码

> vim /etc/my.cnf

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