CentOS7 安装mysql(YUM方式)
1.下载mysql源安装包
shell> wget http://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
2.安装mysql源
shell> yum localinstall mysql80-community-release-el7-1.noarch.rpm
3.检查mysql源是否安装成功
shell> yum repolist enabled | grep "mysql.*-community.*"
4.修改 vim /etc/yum.repos.d/mysql-community.repo源 ,改变默认安装的mysql版本。比如要安装5.6版本,将5.7源的enabled=1改成enabled=0。然后再将5.6源的enabled=0改成enabled=1即可。
5.安装MySQL
shell> yum install mysql-community-server
6.启动MySQL服务
shell> systemctl start mysqld
7.开机启动
shell> systemctl enable mysqld
shell> systemctl daemon-reload
8.修改root本地登录密码
1)查看mysql密码
shell> grep 'temporary password' /var/log/mysqld.log
2)连接mysql
shell> mysql -uroot -p
3)修改密码[注意:后面的分号一定要跟上]
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
或者:
mysql> set password for 'root'@'localhost'=password('MyNewPass4!');
mysql> show variables like '%password%';
9.添加远程登录用户
mysql> GRANT ALL PRIVILEGES ON *.* TO 'caoxiaobo'@'%' IDENTIFIED BY 'Caoxiaobo0917!' WITH GRANT OPTION;
如果此方法不行,那么执行如下脚本:
重新进入mysql命令后 执行如下命令(mysql 8.0下执行如下)
#创建账户
create user 'xiaomage'@'%' identified by 'MyNewPass4!';
#赋予权限,with grant option这个选项表示该用户可以将自己拥有的权限授权给别人
grant all privileges on *.* to 'xiaomage'@'%' with grant option;
#改密码&授权超用户,flush privileges 命令本质上的作用是将当前user和privilige表中的用户信息/权限设置从mysql库(MySQL数据库的内置库)中提取到内存里
flush privileges;