建立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;