Linux下配置mysql數據庫


1 linux下安裝mysql數據庫

               1、將安裝包上傳到linux目錄下

                              /usr/local/wollo

               2、使用 tar命令在當前目錄下解壓mysql

                              解壓命令為:

                                             [root@bogon wollo]# tar -zxvf mysql-5.6.31-linux-glibc2.5-x86_64.tar.gz

               3、將解壓后的mysql文件夾復制到usr目錄下的local目錄中

                              復制命令為:

                                             [root@bogon wollo]# cp -r mysql-5.6.31-linux-glibc2.5-x86_64 /usr/local/mysql

               4、進入到usr/local/mysql目錄下

                              命令為:

                                             [root@bogon wollo]# cd /usr/local/mysql/

               5、在mysql目錄下,創建用戶組

                              命令為:

                                             [root@bogon mysql]# groupadd mysql

               6、在mysql目錄下,創建用戶:

                              命令為:

                                             [root@bogon mysql]# useradd -r  -g mysql mysql

               7、在mysql目錄下,給用戶賦予mysql文件夾的操作權限

                              命令為:

                                             [root@bogon mysql]# chgrp  -R mysql .

               8、在mysql目錄下,變更mysql用戶具備操作本級目錄的權限:

                              命令為:

                                             [root@bogon mysql]# chown -R mysql .

               9、在mysql目錄下,判斷ect/my.cnf文件是否存在,存在則刪除

                              判斷命令為:

                                             [root@bogon mysql]# ls /etc/my.cnf

                              刪除命令為:

                                             [root@bogon mysql]# rm -rf /etc/my.cnf

               10、在mysql目錄下,初始化數據庫

                                             命令為:[root@bogon mysql]# ./scripts/mysql_install_db --user=mysql

               11、在mysql目錄下,將mysql的my-default.cnf文件復制到ect下

                              命令為:

                                             [root@bogon mysql]# cp support-files/my-default.cnf /etc/my.cnf

               12、在mysql目錄下,復制服務文件到etc目錄下

                              命令為:

                                             [root@bogon mysql]# cp support-files/mysql.server      /etc/rc.d/init.d/mysql

               13、在mysql目錄下,啟動mysql服務:

                              命令為:

                                             [root@bogon mysql]# service mysql start

               14、啟動成功后在控制台輸入 mysql -u root -p進入mysql命令行

                                             如果提示沒有mysql命令,則添加軟連接。

                                             命令為:

                                                            [root@bogon mysql]# ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql

               15、再次輸入mysql -u root -p,如果提示mysql密碼,則表示安裝和配置成功

2 mysql的密碼修改

               1、進入/etc/my.cnf 在[mysql]下添加skip-grant-tables 啟動安全模式

命令:vi /etc/my.cnf

               2、重啟服務:

                              命令:service mysql restart

               3、登錄mysql,輸入密碼時直接回車

                              命令:  mysql -u root -p

               4、進入到mysql后,先使用mysql數據庫

                              命令:use mysql

               5、修改密碼

                              命令: update user set password= passworD ("bjsxt") where user='root'

               6、刷新權限

                              命令: flush privileges;

               7、退出

                              命令:exit;

3 mysql的遠程鏈接配置

               1、使用mysql -u root -p 回車,然后輸入密碼,進入到mysql命令狀態

               2、切換為mysql庫

                              命令為:use mysql;

               3、修改root賬戶的鏈接權限

                             命令為: grant all privileges on *.* to root@'%' identified by "bjsxt";

               4、刷新權限

                              命令:flush privileges;

               5、退出

                              命令:exit

               6、在防火牆中放行3306端口號

                              命令: vi /etc/sysconfig/iptables

        7、在Navicat中建立mysql連接

               注意:重啟linux后需要重啟mysql才能用navicat連接

                                             service mysql start 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM