1.查看yum列表,發現沒有mysql [root@server-mysql src]# yum list mysql 已加載插件:fastestmirror Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast Loading mirror speeds from cached hostfile * base: centos.ustc.edu.cn * extras: centos.ustc.edu.cn * updates: centos.ustc.edu.cn 錯誤:沒有匹配的軟件包能夠列出 2.使用wget下載一個mysql的repo源 [root@server-mysql src]# wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm -bash: wget: 未找到命令 3.發現wget也沒有,那就安裝一個wget [root@server-mysql src]# yum list wget 已加載插件:fastestmirror Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast Loading mirror speeds from cached hostfile * base: centos.ustc.edu.cn * extras: centos.ustc.edu.cn * updates: centos.ustc.edu.cn 可安裝的軟件包 wget.x86_64 1.14-15.el7_4.1 base [root@server-mysql src]# yum -y install wget.x86_64 ...... 依賴關係解決 ======================================================================================== Package 架構 版本 源 大小 ======================================================================================== 正在安裝: wget x86_64 1.14-15.el7_4.1 base 547 k 事務概要 ======================================================================================== 安裝 1 軟件包 總下載量:547 k 安裝大小:2.0 M Downloading packages: wget-1.14-15.el7_4.1.x86_64.rpm | 547 kB 00:00:10 Running transaction check Running transaction test Transaction test succeeded Running transaction 正在安裝 : wget-1.14-15.el7_4.1.x86_64 1/1 驗證中 : wget-1.14-15.el7_4.1.x86_64 1/1 已安裝: wget.x86_64 0:1.14-15.el7_4.1 完畢! 4.在次下載mysql的repo源 [root@server-mysql src]# wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm --2018-09-08 14:45:20-- http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm 正在解析主機 repo.mysql.com (repo.mysql.com)... 104.124.241.153 正在鏈接 repo.mysql.com (repo.mysql.com)|104.124.241.153|:80... 已鏈接。 已發出 HTTP 請求,正在等待迴應... 200 OK 長度:6140 (6.0K) [application/x-redhat-package-manager] 正在保存至: 「mysql-community-release-el7-5.noarch.rpm」 100%[========================================================>] 6,140 --.-K/s 用時 0.001s 2018-09-08 14:45:20 (8.39 MB/s) - 已保存 「mysql-community-release-el7-5.noarch.rpm」 [6140/6140]) 5.用命令查看當前目錄,已經下載好了 [root@server-mysql src]# ll | grep mysql -rw-r--r--. 1 root root 6140 11月 12 2015 mysql-community-release-el7-5.noarch.rpm 6.安裝一下 [root@server-mysql src]# rpm -ivh mysql-community-release-el7-5.noarch.rpm 準備中... ################################# [100%] 正在升級/安裝... 1:mysql-community-release-el7-5 ################################# [100%] 7.再次查看yum列表,發現已經有mysql的包了 [root@server-mysql src]# yum list mysql 已加載插件:fastestmirror mysql-connectors-community | 2.5 kB 00:00:00 mysql-tools-community | 2.5 kB 00:00:00 mysql56-community | 2.5 kB 00:00:00 (1/3): mysql-connectors-community/x86_64/primary_db | 26 kB 00:00:00 (2/3): mysql-tools-community/x86_64/primary_db | 45 kB 00:00:00 8.執行安裝(會替換自帶的mariadb庫) [root@server-mysql src]# yum -y install mysql-server 已加載插件:fastestmirror ....... 已安裝: mysql-community-libs.x86_64 0:5.6.41-2.el7 mysql-community-server.x86_64 0:5.6.41-2.el7 做爲依賴被安裝: mysql-community-client.x86_64 0:5.6.41-2.el7 mysql-community-common.x86_64 0:5.6.41-2.el7 net-tools.x86_64 0:2.0-0.22.20131004git.el7 perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.el7 perl-Compress-Raw-Zlib.x86_64 1:2.061-4.el7 perl-DBI.x86_64 0:1.627-4.el7 perl-Data-Dumper.x86_64 0:2.145-3.el7 perl-IO-Compress.noarch 0:2.061-2.el7 perl-Net-Daemon.noarch 0:0.48-5.el7 perl-PlRPC.noarch 0:0.2020-14.el7 替代: mariadb-libs.x86_64 1:5.5.56-2.el7 完畢!
1.嘗試進入mysql, 報錯了,是沒有權限
[root@server-mysql src]# mysql -u root ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) 2.查看mysql所屬的用戶,發現是mysql [root@server-mysql src]# ll /var/lib/ | grep mysql drwxr-xr-x. 2 mysql mysql 6 6月 15 21:36 mysql drwxr-x---. 2 mysql mysql 6 6月 15 21:36 mysql-files 3.將其更改成當前用戶(root) [root@server-mysql src]# chown -R root:root /var/lib/mysql* [root@server-mysql src]# ll /var/lib/ | grep mysql drwxr-xr-x. 2 root root 6 6月 15 21:36 mysql drwxr-x---. 2 root root 6 6月 15 21:36 mysql-files 4.重啓mysql [root@server-mysql src]# systemctl restart mysqld 5.再次進入數據庫,並查看已有數據庫 [root@server-mysql src]# mysql -u root Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.6.41 MySQL Community Server (GPL) Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | +--------------------+ 3 rows in set (0.00 sec)
方式一:
1.登錄到mysql中,將密碼修改成root
mysql> set password for root@localhost = password('root'); Query OK, 0 rows affected (0.00 sec) 2.退出mysql mysql> exit; Bye 3.再次登錄須要使用密碼登錄 [root@server-mysql src]# mysql -u root -p Enter password: root 方式二: 1.登錄到mysql中,切換到mysql庫 mysql> use mysql; 2.直接更新user表 mysql> update user set password=password('root') where user='root' and host='localhost'; 3.刷新權限表 mysql> flush privileges; 方式三: 使用navicat修改,須要使用navicat鏈接上這個數據庫,見文章最後有圖示
1.切換到mysql庫 mysql> use mysql; Database changed 2.查看用戶和能鏈接的主機, 發現root用戶只能在本機鏈接(host中地址都是表明本機),不能遠程用navicat鏈接 mysql> select user, host from user where user = 'root'; +------+--------------+ | user | host | +------+--------------+ | root | 127.0.0.1 | | root | ::1 | | root | localhost | | root | server-mysql | +------+--------------+ 4 rows in set (0.00 sec) 3.修改用戶訪問的地址 mysql> Grant all privileges on *.* to root@'%' identified by 'root' with grant option; Query OK, 0 rows affected (0.00 sec) 說明:*.*指對數據的全部權限(增刪改查), root指鏈接上來的用戶名, ‘%’指全部外部ip地址均可以鏈接上來,若是要指定地址能夠這樣寫 ‘100.100.100.100’, identified by 後跟的是鏈接上來的密碼 4.再次查看, 發現root用戶多了一個主機地址(%) mysql> select user, host from user where user = 'root'; +------+--------------+ | user | host | +------+--------------+ | root | % | | root | 127.0.0.1 | | root | ::1 | | root | localhost | | root | server-mysql | +------+--------------+ 5 rows in set (0.00 sec) 5.刷新一下權限表 mysql> flush privileges; Query OK, 0 rows affected (0.01 sec) 6.開放端口 [root@server-mysql src]# firewall-cmd --add-port=3306/tcp --permanent success [root@server-mysql src]# firewall-cmd --reload success
https://www.jianshu.com/p/c1ac5e732a44
mysql