1. 下载yum的repo源并安装,执行安装后,在/etc/yum.repos.d/
这个目录下多出mysql-community-source.repo
和mysql-community.repo
:
# Centos6.5:
wget http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm
rpm -ivh mysql-community-release-el6-5.noarch.rpm
# Centos7:
wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
rpm -ivh mysql-community-release-el7-5.noarch.rpm
2. 用yum repolist mysql
查看是否已经有mysql可安装文件:
yum repolist all | grep mysql
3. 安装mysql服务:
yum install mysql-community-server
4. 安装成功后,启动mysql服务:
systemctl start mysqld
5. mysql安装后密码默认为空,需要修改密码:
mysql -u root
use mysql;
update user set password=PASSWORD("这里输入root用户密码") where User='root';
flush privileges;
6. 设置mysql服务自启动:
systemctl enable mysqld
7. mysql安全问题:
mysql_secure_installation
Enter current password for root (enter for none): <- 初次运行直接回车
Set root password? [Y/n] <– 是否设置root用户密码,输入y并回车或直接回车
Remove anonymous users? [Y/n] <– 是否删除匿名用户,生产环境建议删除,所以直接回车
Disallow root login remotely? [Y/n] <–是否禁止root远程登录,根据自己的需求选择Y/n并回车
Remove test database and access to it? [Y/n] <– 是否删除test数据库,直接回车
Reload privilege tables now? [Y/n] <– 是否重新加载权限表,直接回车
8.本地远程连接可能会出现1130错误,需要设置root的'host'为'%':
# 以权限用户root登录
mysql -u root -p
# 选择mysql库
use mysql;
# 查看mysql库中的user表的host值
select 'host' from user where user='root';
# 修改host值,如果这步出错'ERROR 1062 (23000): Duplicate entry `%-root` for key `PRIMARY`'说明该记录有了
update user set host = '%' where user ='root';
# 刷新mysql的系统权限相关表
flush privileges;
# 再重新查看user表
select 'host' from user where user='root';
9. 重启mysql服务:
systemctl restart mysqld;
参考文章
- linux CentOS6.5 yum安装mysql 5.6