CentOS7安装MySQL
2018-01-12 本文已影响575人
55eb0b027686
愿你,忠于自己,活得像自己。
清单:
Name | Version |
---|---|
CentOS | 7 |
MySQL | 5.7 |
- 检查是否已经安装MySQL
rpm -qa | grep 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.*"
yum资源列表 - 安装MySQL
# yum install mysql-community-server
- 启动MySQL服务
# systemctl start mysqld
- 设置开机启动(如不需要可跳过)
# systemctl enable mysqld
# systemctl daemon-reload
- 获取MySQL默认密码
# grep 'temporary password' /var/log/mysqld.log
MySQL默认密码 - 修改密码(需包含大小写英文、数字、特殊字符且大于8位)
# mysql -u root -p
# set password for 'root'@'localhost'=password('MySQL@lipuan.2018');
- 配置默认编码utf8,文件/etc/my.cnf中[mysqld]下加入
character_set_server=utf8
init_connect='SET NAMES utf8'
-
关键目录
配置文件: /etc/my.cnf
日志文件: /var/log//var/log/mysqld.log
服务启动脚本: /usr/lib/systemd/system/mysqld.service
socket文件: /var/run/mysqld/mysqld.pid -
忘记密码操作,文件/etc/my.cnf中[mysqld]下加入
skip-grant-tables
重启MySQL
# service mysqld restart
转至步骤9修改密码,成功后删除文件/etc/my.cnf中的skip-grant-tables