Centos7下使用yum安装mysql,详细步骤1. 下载mysql的repo源$ wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm 2. 安装mysql-community-release-el7-5.noarch.rpm包$ sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm 安装这个包后,会获得两个mysql的yum repo源:/etc/yum.repos.d/mysql-community.repo,/etc/yum.repos.d/mysql-community-source.repo。 3. 安装mysql$ sudo yum install mysql-server 根据步骤安装就可以了,不过安装完成后,没有密码,需要重置密码。 4. 重置密码重置密码前,首先要登录 $ mysql -u root 登录时有可能报这样的错:ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘ (2),原因是/var/lib/mysql的访问权限问题。下面的命令把/var/lib/mysql的拥有者改为当前用户: $ sudo chown -R openscanner:openscanner /var/lib/mysql 然后,重启服务: $ service mysqld restart 5. 防火墙设置,开放3306端口firewall-cmd --permanent --zone=public --add-port=3306/tcp firewall-cmd --permanent --zone=public --add-port=3306/udp firewall-cmd --reload 6. mysql安全设置mysql_secure_installation; MySQL 会提示你重置 root 密码,移除其他用户账号,禁用 root 远程登录,移除 test 数据库,重新加载 privilege 表格等。 7. 创建远程访问用户--实施环境用户 CREATE USER 'dbuser'@'%' IDENTIFIED BY '123456'; GRANT SELECT,INSERT,UPDATE,DELETE ON *.* TO 'dbuser'@'%'; --管理员用户 CREATE USER 'admin'@'%' IDENTIFIED BY '123456'; CREATE USER 'admin'@'%' IDENTIFIED BY '123456'; GRANT ALL ON *.* TO 'admin'@'%'; flush privileges; 8. 更改数据存放目录mkdir /home/data --关闭mysql服务进程 systemctl status mysqld mv /var/lib/mysql /home/data 修改 /etc/my.cnf 文件 [mysqld] datadir=/home/data/mysql socket=/home/data/mysql/mysql.sock [mysql] socket=/home/data/mysql/mysql.sock(责任编辑:好模板) |