CentOS7下mysql安裝

來源:互聯網
上載者:User

標籤:

CentOS7下安裝MySQL


--下載mysql
http://mirrors.sohu.com/mysql/MySQL-5.6/
http://mirrors.sohu.com/mysql/MySQL-5.6/MySQL-5.6.24-1.linux_glibc2.5.x86_64.rpm-bundle.tar


一。準備工作
--下載後檔案
MySQL-5.6.24-1.linux_glibc2.5.x86_64.rpm-bundle.tar


--建立檔案夾
mkdir /home/www/tar
mkdir /home/www/rpm


--上傳檔案至rpm包下解壓
tar -xvf MySQL-5.6.24-1.linux_glibc2.5.x86_64.rpm-bundle.tar
...
MySQL-5.6.24-1.linux_glibc2.5.x86_64.rpm-bundle.tar
MySQL-client-5.6.24-1.linux_glibc2.5.x86_64.rpm
MySQL-devel-5.6.24-1.linux_glibc2.5.x86_64.rpm
MySQL-embedded-5.6.24-1.linux_glibc2.5.x86_64.rpm
MySQL-server-5.6.24-1.linux_glibc2.5.x86_64.rpm
MySQL-shared-5.6.24-1.linux_glibc2.5.x86_64.rpm
MySQL-shared-compat-5.6.24-1.linux_glibc2.5.x86_64.rpm
MySQL-test-5.6.24-1.linux_glibc2.5.x86_64.rpm

--把tar檔案移至/home/www/tar
mv MySQL-5.6.24-1.linux_glibc2.5.x86_64.rpm-bundle.tar /home/www/tar


二、開始安裝
--開始安裝(其中,v表示顯示詳細安裝資訊,h表示顯示用#表示安裝進度)
rpm -ivh MySQL-*


--看到如下資訊已安裝成功
A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER !
You will find that password in ‘/root/.mysql_secret‘.
...
...
New default config file was created as /usr/my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings


備忘:最新版的MySQL將隨機產生一個root使用者的密碼,放在/root/.mysql_secret 檔案中


--查看連接埠(預設3306)
[[email protected] init.d]# netstat -nat
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 0.0.0.0:3690            0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN     
tcp        0      0 192.168.1.110:22        192.168.1.119:50608     ESTABLISHED
tcp6       0      0 :::3306                 :::*                    LISTEN     
tcp6       0      0 :::22                   :::*                    LISTEN


三、安裝位置
用RPM進行安裝的時候,MySQL下的子目錄被分散開,分別放在了以下幾個目錄下:
/etc/logrotate.d/mysql
/etc/rc.d/init.d/mysql // mysql啟動配置指令碼,其中只有一個叫mysql的可執行檔 與mysql有關
/var/lib/mysql // Mysql中的資料庫存放目錄
/var/lock/subsys/mysql
/usr/lib/mysql                  //  該檔案夾下是mysql連結庫
/usr/include/mysql //  mysql 標頭檔
/usr/share/mysql //  mysql 安裝目錄
/usr/bin // 其中有mysql的多個可執行程式,如mysql、mysql_config_editor、mysqlcheck、mysqladmin等


四、mysql停止與重啟
/etc/rc.d/init.d/mysql restart
/etc/rc.d/init.d/mysql stop
/etc/rc.d/init.d/mysql start


五、錯誤排查
[[email protected] rpm]# mysql -uroot
--出現問題
(1)報錯:ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: NO)
--停止服務
/etc/rc.d/init.d/mysql stop
--安全模式進入mysql
[[email protected] rpm]# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
[[email protected] rpm]# mysql -u root mysql
--更改使用者名稱
mysql> UPDATE user SET Password=PASSWORD(‘root‘) where User=‘root‘;
mysql> FLUSH PRIVILEGES;
mysql> quit
[[email protected] rpm]# mysql -uroot -p
mysql> show databases;
(2)報錯:ERROR 1820 (HY000): You must SET PASSWORD before executing this statement
--重新設定root密碼
mysql> SET PASSWORD = PASSWORD(‘root‘);
Query OK, 0 rows affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)


(3)navicat報錯:Host ‘192.168.1.*‘ is not allowed to connect to this MySQL server
原因:mysql下user表中不允許外部連結
--臨時把連接埠加入防火牆
firewall-cmd --permanent --zone=public --add-port=3306/tcp
systemctl restart firewalld.service
--更改host
[[email protected] rpm]# mysql -uroot -p
mysql> use mysql
mysql> select host, user from user;
+-----------------------+------+
| host                  | user |
+-----------------------+------+
| 127.0.0.1             | root |
| ::1                   | root |
| localhost             | root |
| localhost.localdomain | root |
+-----------------------+------+
4 rows in set (0.00 sec)
--更改localhost為%
mysql> update user set host = ‘%‘ where host=‘localhost‘;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select host, user from user;
+-----------------------+------+
| host                  | user |
+-----------------------+------+
| %                     | root |
| 127.0.0.1             | root |
| ::1                   | root |
| localhost.localdomain | root |
+-----------------------+------+
4 rows in set (0.00 sec)
--重啟mysql服務
/etc/rc.d/init.d/mysql restart

至此mysql已可以正常使用!


六、開機啟動
使用命令:sbin/chkconfig --list,查看啟動項
使用命令:sbin/chkconfig --add mysql,將mysql添加到開機啟動項中:
使用命令:sbin/chkconfig --del mysql,將mysql從開機啟動項中刪除:



CentOS7下mysql安裝

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.