1. 程式人生 > >Mysql數據庫安裝使用過程

Mysql數據庫安裝使用過程

state mysql安裝 pre connect mon pri mysql數據庫 src iptable

環境說明:
操作系統:Red Hat Linux 6
安裝Mysql5.7版本

安裝須知:
一、準備mysql的安裝包
二、準備好安裝環境

操作指導:
一、下載mysql的安裝包
https://www.mysql.com/downloads/ 訪問mysql下載地址,進行如下操作進行下載。

技術分享圖片

技術分享圖片

技術分享圖片

技術分享圖片

將下載好的mysql安裝包放到自己建立的安裝目錄下,進行解壓。

[root@root /]# cd /soft/
[root@root soft]# ll
總用量 1151432
-rw-r--r--. 1 root root  227512320 8月   7 17:59 MySQL-5.6.41-1.el6.x86_64.rpm-bundle.tar
-rw-r--r--. 1 root root  475770880 8月   7 18:21 mysql-5.7.23-1.el6.x86_64.rpm-bundle.tar
-rw-r--r--. 1 7155 31415  24024136 6月  11 11:21 mysql-community-client-5.7.23-1.el6.x86_64.rpm
-rw-r--r--. 1 7155 31415    340072 6月  11 11:21 mysql-community-common-5.7.23-1.el6.x86_64.rpm
-rw-r--r--. 1 7155 31415   3736628 6月  11 11:21 mysql-community-devel-5.7.23-1.el6.x86_64.rpm
-rw-r--r--. 1 7155 31415  39496088 6月  11 11:21 mysql-community-embedded-5.7.23-1.el6.x86_64.rpm
-rw-r--r--. 1 7155 31415 137638820 6月  11 11:21 mysql-community-embedded-devel-5.7.23-1.el6.x86_64.rpm
-rw-r--r--. 1 7155 31415   2192692 6月  11 11:21 mysql-community-libs-5.7.23-1.el6.x86_64.rpm
-rw-r--r--. 1 7155 31415   1723712 6月  11 11:21 mysql-community-libs-compat-5.7.23-1.el6.x86_64.rpm
-rw-r--r--. 1 7155 31415 160480880 6月  11 11:21 mysql-community-server-5.7.23-1.el6.x86_64.rpm
-rw-r--r--. 1 7155 31415 106124936 6月  11 11:21 mysql-community-test-5.7.23-1.el6.x86_64.rpm

二、準備好安裝環境
檢查當前系統下是否有mysql服務,方法: rpm -qa | grep mysql。 如果有就用rpm卸載掉。可以使用的命令是 rpm -ev 程序(如果卸載報存在依賴關系問題就用,rpm -e --nodeps 程序 進行卸載, --nodeps 跳過依賴關系)

[root@root mysql]# rpm -qa | grep mysql
mysql-libs-5.1.71-1.el6.x86_64
root@root mysql]# rpm -ev mysql-libs-5.1.71-1.el6.x86_64  /*報依賴關系*/
error: Failed dependencies:
        libmysqlclient.so.16()(64bit) is needed by (installed) postfix-2:2.6.6-2.2.el6_1.x86_64
        libmysqlclient.so.16(libmysqlclient_16)(64bit) is needed by (installed) postfix-2:2.6.6-2.2.el6_1.x86_64
[root@root soft]# rpm -e --nodeps mysql-libs-5.1.71-1.el6.x86_64  /*卸載不含依賴關系*/
[root@root soft]# 

三、進行mysql服務安裝
進入到mysql包的解壓目錄下,用rpm進行安裝。註意安裝順序,否則或報依賴關系錯誤。

[root@root soft]# rpm -ivh mysql-community-common-5.7.23-1.el6.x86_64.rpm
[root@root soft]# rpm -ivh mysql-community-libs-5.7.23-1.el6.x86_64.rpm
[root@root soft]# rpm -ivh mysql-community-client-5.7.23-1.el6.x86_64.rpm
[root@root soft]# rpm -ivh mysql-community-server-5.7.23-1.el6.x86_64.rpm

安裝完成,修改配置文件。在/etc/my.cnf

[root@root etc]# vim my.cnf
[mysqld]
skip-grant-tables  /*添加,作用可以不用密碼進行登錄*/

啟動mysql服務,輸入mysql就可以進入數據庫。(啟用成功可以用 netstat -nlap | grep mysql 查看mysql服務)

[root@root soft]# service mysqld start
[root@root soft]# mysql  
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 23
Server version: 5.7.23 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> 

這時,你可以使用navicat工具連接mysql服務了。如果連接不上,請檢查3306端口是否開發,可以嘗試關閉linux防火墻。service iptables stop

嘗試連接成功後,我們可以為mysql服務設置密碼。
先選擇用戶

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> update user set authentication_string = password(‘111111‘), password_expired = ‘N‘, password_last_changed = now() where user = ‘root‘;
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1
mysql> flush privileges; /*刷入配置,必須執行,否則後期錯誤信息*/
Query OK, 0 rows affected (0.00 sec)
mysql> 

註:這個設置密碼方式如果不對,可以嘗試其它方法設置密碼(如:mysqladmin -u root password “11111111”)。設置完密碼切記要去my.cnf配置文件把skip-grant-tables 註釋掉,在重啟mysql服務。這是就可使用用戶名密碼登錄。

navicat使用指南:http://www.formysql.com/mysql/jiqiao/

Mysql數據庫安裝使用過程