centons 7 安装mysql
1 CentOS 7 yum安装mysql
1.1 Yum 安装mysql
CentOS用yum安装相对省事,省去很多配置环节
安装mysql 源
yum localinstall http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
安装mysql
yum install -y mysql-community-server
安装mysql的开发包,以后会用到
yum install –y mysql-community-devel
1.1.1 启动MySQL服务
命令:systemctl start mysqld
开机启动命令:#systemctl enable mysqld
# systemctl daemon-reload
查看mysql启动状态命令:service mysqld status
1.1.2 修改root默认密码
修改密码策略
在/etc/my.cnf文件设置,如果不需要密码策略,添加my.cnf文件中添加如下配置禁用即可:
validate_password = off
重新启动mysql服务使配置生效
1.1.3 重新启动mysql服务使配置生效:
重启服务命令: systemctl restart mysqld
mysql安装完成之后,在/var/log/mysqld.log文件中给root生成了一个默认密码。通过下面的方式找到root默认密码,然后登录mysql进行修改:
#grep 'temporary password' /var/log/mysqld.log
mysql
-uroot-p
mysql
>ALTER USER
'root'@
'localhost'IDENTIFIED
BY'root'
;
注意:mysql5.7默认安装了密码安全检查插件(validate_password),默认密码检查策略要求密码必须包含:大小写字母、数字和特殊符号,并且长度不能少于8位。否则会提示ERROR 1819 (HY000): Your password does not satisfy the current policy requirements错误,如下图所示:
1.1.4 添加远程登入用户
把在所有数据库的所有表的所有权限赋值给位于所有IP地址的root用户。
mysql> grant all privileges on *.* to root@'%'identified by 'password';
如果是新用户而不是root,则要先新建用户
mysql>create user 'username'@'%' identified by 'password';
此时就可以进行远程连接了。
1.1.5 配置默认编码为utf8
修改/etc/my.cnf配置文件,在[mysqld]下添加编码配置,如下所示:
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
重新启动mysql服务,查看数据库默认编码如下所示:
默认配置文件路径:配置文件:/etc/my.cnf 日志文件:/var/log//var/log/mysqld.log
服务启动脚本:/usr/lib/systemd/system/mysqld.service socket文件:/var/run/mysqld/mysqld.pid
1.2 卸载mysql
查看yum是否安装过mysql
命令:yum list installed mysql*
yum 卸载
根据上面列表的名字
yum remove mysql-community-client mysql-community-common mysql-community-libs mysql-community-libs-compat mysql-community-server mysql57-community-release
rm -rf /var/lib/mysql
rm /etc/my.cnf
rpm查看安装
命令:rpm -qa | grep -i mysql
rpm 卸载
rpm -e mysql57-community-release-el7-9.noarch
rpm -e mysql-community-server-5.7.17-1.el7.x86_64
rpm -e mysql-community-libs-5.7.17-1.el7.x86_64
rpm -e mysql-community-libs-compat-5.7.17-1.el7.x86_64
rpm -e mysql-community-common-5.7.17-1.el7.x86_64
rpm -e mysql-community-client-5.7.17-1.el7.x86_64
cd /var/lib/
rm -rf mysql/
清除余项
whereis mysql
mysql: /usr/bin/mysql /usr/lib64/mysql /usr/local/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz
# 删除上面的文件夹
rm -rf /usr/bin/mysql
…
删除配置
1 2 |
rm –rf /usr/my.cnf rm -rf /root/.mysql_sercret |
剩余配置检查
1 2 |
chkconfig --list | grep -i mysql chkconfig --del mysqld |