1. 程式人生 > >Linux伺服器---安裝mysql

Linux伺服器---安裝mysql

安裝mysql

1、檢測是否已安裝mysql

[[email protected] bin]# rpm -qa | grep mysql

mysql-libs-5.1.71-1.el6.i686

[[email protected] bin]

 

2、安裝mysql和mysql-server 

[[email protected] bin]# yum install -y mysql

[[email protected] bin]# yum install -y mysql-server

 

3、啟動mysql,注意這裡的服務名字是“mysqld”

[[email protected] bin]# service mysqld start

shell-init: error retrieving current directory: getcwd: cannot access parent directories: 沒有那個檔案或目錄

chdir: error retrieving current directory: getcwd: cannot access parent directories: 

沒有那個檔案或目錄

初始化 MySQL 資料庫: Installing MySQL system tables...

OK

Filling help tables...

OK                                                         [

確定]

正在啟動 mysqld                                          [確定]

[[email protected] bin]# 

 

4、配置MySQL開機啟動 

[[email protected] bin]# chkconfig mysqld on

[[email protected] bin]# chkconfig --list mysqld

mysqld         0:關閉  1:關閉  2:啟用  3:啟用  4:啟用  5:啟用  6:關閉

[[email protected] bin]# 

 

5、設定root使用者密碼 ,設定密碼的命令是“mysqladmin -u 使用者名稱password密碼

[[email protected] bin]# mysqladmin -u root password 543092   //密碼是543092

 

6、修改密碼,命令是“mysqladmin -u 使用者名稱-p password 新密碼” 

[[email protected] bin]# mysqladmin -u root -p password 123456     //新密碼123456

Enter password:        //這裡要求輸入舊密碼

[[email protected] bin]# 

 

7、mysql配置檔案“/etc/my.cnf” 

[[email protected] bin]# cat /etc/my.cnf 

[mysqld]

datadir=/var/lib/mysql            //資料庫檔案目錄

socket=/var/lib/mysql/mysql.sock    //socket檔案

user=mysql

# Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0

 

[mysqld_safe]

log-error=/var/log/mysqld.log     //日誌檔案

pid-file=/var/run/mysqld/mysqld.pid    //程序pid檔案

 

 

8、修改埠

1)mysql預設的埠是3306,可以使用netstat來檢視

[[email protected] bin]# netstat -tunlp | grep mysqld

tcp        0      0 0.0.0.0:3306               0.0.0.0:*                  LISTEN      4339/mysqld         

2)埠在配置檔案中修改,開啟配置檔案,在後面追加一句話”port=xxx” 

[[email protected] bin]# gedit /etc/my.cnf

port=3307      

3)重啟myslqd服務,檢視埠 

[[email protected] bin]# service mysqld restart

shell-init: error retrieving current directory: getcwd: cannot access parent directories: 沒有那個檔案或目錄

chdir: error retrieving current directory: getcwd: cannot access parent directories: 沒有那個檔案或目錄

^[[A停止mysqld                                          [確定]

正在啟動mysqld                                          [確定]

[[email protected] bin]# netstat -tunlp | grep mysqld

tcp        0      0 0.0.0.0:3307               0.0.0.0:*                   LISTEN      4604/mysqld