1. 程式人生 > >在centos7中使用yum安裝mysql資料庫並使用navicat連線

在centos7中使用yum安裝mysql資料庫並使用navicat連線

1.安裝
1.檢視yum列表,發現沒有mysql
[[email protected] 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源 [
[email protected]
src]# wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm -bash: wget: 未找到命令 3.發現wget也沒有,那就安裝一個wget [[email protected] 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 [
[email protected]
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源 [
[email protected]
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.用命令檢視當前目錄,已經下載好了 [[email protected] src]# ll | grep mysql -rw-r--r--. 1 root root 6140 11月 12 2015 mysql-community-release-el7-5.noarch.rpm 6.安裝一下 [[email protected] src]# rpm -ivh mysql-community-release-el7-5.noarch.rpm 準備中... ################################# [100%] 正在升級/安裝... 1:mysql-community-release-el7-5 ################################# [100%] 7.再次檢視yum列表,發現已經有mysql的包了 [[email protected] 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庫) [[email protected] 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 完畢!
2.初始化
1.嘗試進入mysql,  報錯了,是沒有許可權
[[email protected] 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
[[email protected] 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)
[[email protected] src]# chown -R root:root /var/lib/mysql*
[[email protected] 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
[[email protected] src]# systemctl restart mysqld

5.再次進入資料庫,並檢視已有資料庫
[[email protected] 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) 

3.設定/修改密碼

方式一:
    1.登陸到mysql中,將密碼修改為root
    mysql> set password for [email protected] = password('root');
        Query OK, 0 rows affected (0.00 sec)

    2.退出mysql
    mysql> exit;
        Bye

    3.再次登陸需要使用密碼登陸
    [[email protected] 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連線上這個資料庫,見文章最後有圖示 

4.修改遠端連線許可權

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 [email protected]'%' 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.開放埠 [[email protected] src]# firewall-cmd --add-port=3306/tcp --permanent success [[email protected] src]# firewall-cmd --reload success 

5.使用navicat連線資料庫

       
6.使用navicat修改使用者密碼
     




https://www.jianshu.com/p/c1ac5e732a44