创建mysql的yum源文件,其他默认的yum源的配置文件不用动
vi mysql.repo
[mysql]
name=mysql
baseurl=https://mirrors.cloud.tencent.com/mysql/yum/mysql-5.6-community-el7-x86_64/
enabled=1
gpgcheck=0
yum clean all
yum makecache fast
yum install -y mysql-community-server
yum -y install mysql-community-server ansible
systemctl start mysqld
默认没有密码
mysql -u root -p
添加密码
grant all on *.* to root@'%' identified by 'Tredis';
grant all on *.* to root@'localhost' identified by 'Tredis';
grant all on *.* to root@'test' identified by 'myPassword';
flush privileges;
卸载MySQL的步骤:
1.查看是否安装Mysql
[atguigu@hadoop102 module]$ rpm -qa | grep -i mysql
MySQL-client-5.6.24-1.el6.x86_64
MySQL-server-5.6.24-1.el6.x86_64
2.查看MySQL服务是否启动,关闭
[atguigu@hadoop102 module]$ sudo service mysql status
[sudo] password for atguigu:
MySQL running (2681) [确定]
[atguigu@hadoop102 module]$ sudo service mysql stop
Shutting down MySQL… [确定]
3.卸载MySQL安装的组件
[atguigu@hadoop102 module]$ sudo rpm -e MySQL-server-5.6.24-1.el6.x86_64
[sudo] password for atguigu:
[atguigu@hadoop102 module]$ sudo rpm -e MySQL-client-5.6.24-1.el6.x86_64
4.查找并删除MySQL相关的文件
[atguigu@hadoop102 module]$ whereis mysql
mysql: /usr/lib64/mysql
[atguigu@hadoop102 module]$ sudo find / -name mysql
/var/lib/mysql
/var/lib/mysql/mysql
/usr/lib64/mysql
[atguigu@hadoop102 module]$ sudo rm -rf /var/lib/mysql
[atguigu@hadoop102 module]$
sudo rm -rf /usr/lib64/mysql
2.4 MySql安装
2.4.1 安装包准备
1.查看mysql是否安装,如果安装了,卸载mysql
(1)查看
[root@hadoop102 桌面]# rpm -qa|grep mysql
mysql-libs-5.1.73-7.el6.x86_64
(2)卸载
[root@hadoop102 桌面]# rpm -e --nodeps mysql-libs-5.1.73-7.el6.x86_64
2.解压mysql-libs.zip文件到当前目录
[root@hadoop102 software]# unzip mysql-libs.zip
[root@hadoop102 software]# ls
mysql-libs.zip
mysql-libs
3.进入到mysql-libs文件夹下
[root@hadoop102 mysql-libs]# ll
总用量 76048
-rw-r–r--. 1 root root 18509960 3月 26 2015 MySQL-client-5.6.24-1.el6.x86_64.rpm
-rw-r–r--. 1 root root 3575135 12月 1 2013 mysql-connector-java-5.1.27.tar.gz
-rw-r–r--. 1 root root 55782196 3月 26 2015 MySQL-server-5.6.24-1.el6.x86_64.rpm
2.4.2 安装MySql服务器
1.安装mysql服务端
[root@hadoop102 mysql-libs]# rpm -ivh MySQL-server-5.6.24-1.el6.x86_64.rpm
2.查看产生的随机密码
[root@hadoop102 mysql-libs]# cat /root/.mysql_secret
OEXaQuS8IWkG19Xs
3.查看mysql状态
[root@hadoop102 mysql-libs]# service mysql status
4.启动mysql
[root@hadoop102 mysql-libs]# service mysql start
2.4.3 安装MySql客户端
1.安装mysql客户端
[root@hadoop102 mysql-libs]# rpm -ivh MySQL-client-5.6.24-1.el6.x86_64.rpm
2.链接mysql
[root@hadoop102 mysql-libs]# mysql -uroot -pOEXaQuS8IWkG19Xs
3.修改密码
mysql>SET PASSWORD=PASSWORd('000000');
4.退出mysql
mysql>exit
2.4.4 MySql中user表中主机配置
配置只要是root用户+密码,在任何主机上都能登录MySQL数据库。
1.进入mysql
[root@hadoop102 mysql-libs]# mysql -uroot -p000000
2.显示数据库
mysql>show databases;
3.使用mysql数据库
mysql>use mysql;
4.展示mysql数据库中的所有表
mysql>show tables;
5.展示user表的结构
mysql>desc user;
6.查询user表
mysql>select User, Host, Password from user;
7.修改user表,把Host表内容修改为%
mysql>update user set host='%' where host='localhost';
8.删除root用户的其他host
mysql>delete from user where Host='hadoop102';
mysql>delete from user where Host='127.0.0.1';
mysql>delete from user where Host='::1';
9.刷新
mysql>flush privileges;
10.退出
mysql>quit;