前提准备:
MySQL下载 MySQL :: Download MySQL Community Server
当前安装版本5.7
1.检查是否安装mysql:rpm -aq | grep mysql
如果有输出则先停止服务: service mysqld start
批量删除包 rpm -e XXX --nodeps
2.检查mariadb:rpm -qa|grep mariadb
如果有输出则删除相关包 rpm -e XXX --nodeps
3.删除目录:find / -name mysql
如果有根据目录进行删除: rm -rf XXX
4.删除 my.conf: rm -rf my.conf
5.创建mysql目录: mkdir /usr/local/mysql
6.复制安装包到该目录下:cp ~/download/mysql-5.7.12-1.el6.x86_64.rpm-bundle.tar /usr/local/mysql/
7.解压缩安装包:
cd /usr/local/mysql/
tar -xf mysql-5.7.12-1.el6.x86_64.rpm-bundle.tar
安装libaio
yum install libaio
8.按顺序执行如下安装:
rpm -ivh mysql-community-common-5.7.12-1.el6.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.12-1.el6.x86_64.rpm
rpm -ivh mysql-community-client-5.7.12-1.el6.x86_64.rpm
rpm -ivh imysql-community-server-5.7.12-1.el6.x86_64.rpm
rpm -ivh mysql-community-devel-5.7.12-1.el6.x86_64.rpm
9.启动mysql: systemctl start mysqld.service
10.查看启动状态:systemctl status mysqld.service
11.启动之后密码就创建好了,通过:sudo grep 'temporary password' /var/log/mysqld.log 查看密码
12.登录mysql:mysql -uroot -p
13.修改密码:
set password for 'username '@'host '='password ';
(username --用户名/ host -- 主机地址/ password --密码)
14.创建用户:
create user 'username'@'host' identified by 'password';
(username --用户名/ host -- 主机地址/ password --密码)
15.授权用户:
grant privileges on databasename.tablename TO 'username'@'host';
(databasename --数据库名称/ tablename --表名称/ *代表全部/ username -- 用户名)
16.设置某用户允许外网访问:
(要允许用户帐户从主机的任何子域连接到数据库服务器,使用百分比通配符%)
use mysql;
select user,host from user;
update user set host='%' where user='root';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
flush privileges;