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使用者的password,放在/root/.mysql_secret 檔案裡


--查看port(預設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
--更改username
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
--又一次設定rootpassword
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表中不同意外部連結
--暫時把port增加防火牆
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.