LAMP環境配置之安裝Mysql

安裝MySQL數據庫管理系統mysql

服務器:CentOS6.5linux

Mysql:mysql-5.6.1.tar.gzios

須要使用cmake 編譯,請先安裝cmakeredis

一、增長用戶名和用戶組 #groupadd mysql 
#useradd -g mysql mysql 
二、進入源碼包使用configure 檢查並配置安裝須要的系統環境,並生成安裝配置文件 
sql

#./configure \ 
>--prefix=/usr/local/mysql \  //將軟件安裝在/usr/local/mysql目錄下 
數據庫

>--enable-thread-safe-client \ 
>--with-extra-charsets=all  //在安裝mysql時安裝全部字符集   
若是遇到錯誤信息: 
checking for tgetent in -lncurses... no checking for tgetent in -lcurses... no checking for tgetent in -ltermcap... no 
checking for termcap functions library... configure: error: No curses/termcap library found 
緣由:缺乏ncurses安裝包 解決方案: 
執行下面三行命令,執行完以後從新
apache

./configure(配置) 安全

yum list|grep ncurses 服務器

yum -y install ncurses-devel socket

yum install ncurses-devel 

接着#make && make install 
三、建立mysql數據庫服務器的配置文件,可使用源碼包support-files目錄中的my-medium.cnf文件做爲模板,將其複製到/etc/目錄下,命名爲my.cnf文件便可。 

[root@localhost  mysql-5.0.18]# cp support-files/my-medium.cnf /etc/my.cnf 

四、若是還沒安裝過MySQL,必須建立MySQL受權表。進入到安裝目錄/usr/local/mysql下,執行bin目錄下的mysql_install_db腳本,用來初始化MySQL數據庫的受權表,其中存儲了服務器訪問容許。 
[root@localhost  mysql-5.0.18]#cd /usr/local/mysql 
[root@localhost  mysql]# bin/mysql_install_db --user=mysql  //
建立受權表 

若是使用root用戶運行上面的命令,應當使用--user選項,選項的值應當與你在第一步爲運行服務器所建立的登陸帳戶(mysql用戶)相同。若是用mysql用戶登陸來運行上面的命令,能夠省略--user選項。用mysql_install_db建立mysql受權表後,須要手動從新啓動服務器。 

五、將程序二進制的全部權改成root用戶,數據目錄的全部權改成運行mysqld程序的mysql用戶。若是如今位於安裝目錄(/usr/local/mysql)下,命令行以下: 
[root@localhost  mysql]# chown -R root .(注意有點)  //將文件的全部屬性改成root用戶 
[root@localhost  mysql]# chown -R mysql var  //將數據目錄的全部屬性改成mysql用戶 [root@localhost mysql]# chgrp -R mysql .  //將組屬性改成mysql組   
[root@localhost mysql]# ls -l total 40 
drwxr-xr-x. 2 root  mysql 4096 Feb  7 20:50 bin drwxr-xr-x. 3 root  mysql 4096 Feb  7 20:50 include drwxr-xr-x. 2 root  mysql 4096 Feb  7 20:50 info drwxr-xr-x. 3 root  mysql 4096 Feb  7 20:50 lib drwxr-xr-x. 2 root  mysql 4096 Feb  7 20:50 libexec drwxr-xr-x. 3 root  mysql 4096 Feb  7 20:50 man drwxr-xr-x. 7 root  mysql 4096 Feb  7 20:50 mysql-test drwxr-xr-x. 3 root  mysql 4096 Feb  7 20:50 share drwxr-xr-x. 5 root  mysql 4096 Feb  7 20:50 sql-bench drwx------. 4 mysql mysql 4096 Feb  7 20:53 var   
六、在所須要的東西被安裝完成後,應當使用下面的命令啓動MySQL服務了,命令行以下: [root@localhost mysql]#/usr/local/mysql/bin/mysqld_safe --user=mysql & 報告信息(不理會): 
[root@localhost mysql]# /usr/local/mysql/bin/mysqld_safe --user=mysql & [1] 4720
[root@localhost mysql]# nohup: ignoring input and redirecting stderr to stdout Starting mysqld daemon with databases from /usr/local/mysql/var 
七、MySQL數據庫服務器啓動以後,查看一下它的端口3306是否打開,若是看到如下結果代表mysql服務啓動成功。命令行以下 
[root@localhost mysql]# netstat -tnl|grep 3306 
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                  LISTEN 
八、使用mysqladmin驗證服務器在運行中。如下命令提供了簡單的測試,可檢查服務器是否已經開啓並能響應鏈接。命令行以下: 
[root@localhost mysql]# bin/mysqladmin  version Enter password:  
bin/mysqladmin  Ver 8.41 Distrib 5.0.18, for pc-linux-gnu on i686 Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB This software comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to modify and redistribute it under the GPL license  
Server version          5.0.18-log Protocol version        10 
Connection              Localhost via UNIX socket UNIX socket             /tmp/mysql.sock Uptime:                 18 min 59 sec  
Threads: 1  Questions: 3  Slow queries: 0  Opens: 0  Flush tables: 1  Open tables: 6  Queries per second avg: 0.003 
[root@localhost mysql]# bin/mysqladmin variables //查看全部mysql參數   
九、設置訪問權限,在mysql安裝過程當中,使用mysql_install_db程序安裝了mysql數據庫受權表,表定義了初始mysql用戶帳戶和訪問權限,全部初始化帳戶均沒有密碼。這些帳戶爲超用戶帳戶,能夠執行任何操做。初始root帳戶的密碼爲空,所以任何人能夠用root帳戶不用任何密碼來鏈接mysql服務器,並具備全部權限,這意味着mysql安裝未受保護。若是你想要防止客戶端不使用密碼用匿名用戶來鏈接,你應當爲匿名帳戶指定密碼或刪掉匿名賬戶,應當爲mysql root帳戶指定密碼。使用mysql -u root啓動mysql客戶端控制檯,鏈接mysql服務器。命令行以下:
[root@localhost mysql]# bin/mysql -u root  //沒有密碼可直接登陸本機服務器 Welcome to the MySQL monitor.  Commands end with  or \g. Your MySQL connection id is 5 to server version: 5.0.18-log  
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.   
十、若是有匿名帳戶存在,它擁有所有的權限,所以刪掉它能夠提升安全,在mysql客戶端執行SQL語以下: 
mysql> delete from mysql.user where host='localhost' and user=''; Query OK, 1 row affected (0.01 sec)   
mysql> flush privileges; 
Query OK, 0 rows affected (0.00 sec)   
十一、能夠用幾種方法爲root帳戶指定密碼,咱們選擇用其中的一種。在mysql客戶端命令行上使用set password指定密碼,必定要使用password()函數來加密密碼。例以下面設置localhost域的密碼爲ios100。其餘域可使用一樣的語句,使用的SQL語句以下。 mysql> set password for 'root'@'localhost'=password('ios100'); Query OK, 0 rows affected (0.00 sec)   
十二、若是想退出mysql客戶端,能夠在mysql客戶端提示符下輸入命令exit或者quit,還能夠按鍵盤ctrl+c組合鍵,均可以從mysql客戶端退出。由於已經給mysql服務器的root帳號設置了密碼,因此再次登陸mysql客戶端就要提供密碼才能進入。退出mysql客戶端和從新啓動mysql客戶端的控制檯命令以下。 mysql> exit Bye 
[root@localhost mysql]# bin/mysql -u root -h localhost -p Enter password:  
Welcome to the MySQL monitor.  Commands end with  or \g. Your MySQL connection id is 6 to server version: 5.0.18-log  
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.  
若是想關閉mysql服務器,在命令行使用mysql服務器的mysqladmin命令,經過-u參數給出mysql數據庫管理員用戶名root和經過-p參數給出密碼,便可關閉mysql服務器。以下
示: 

[root@localhost mysql]# bin/mysqladmin -u root -p shutdown Enter password:  
STOPPING server from pid file /usr/local/mysql/var/localhost.pid 130207 21:27:05  mysqld ended  
[1]+  Done                    /usr/local/mysql/bin/mysqld_safe --user=mysql    
1三、mysql服務器和apache服務器同樣也有必要設置爲開機自動運行,設置方法進入到mysql源代碼目錄/usr/local/src/mysql-5.0.18,將子目錄support-files下的mysql.server文件複製到/etc/rc.d/init.d目錄中,並重命名爲mysqld,命令行以下。 

[root@localhost mysql]# cd /usr/local/src/mysql-5.0.18 

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

修改一下權限 
[root@localhost mysql-5.0.18]# chown root.root /etc/rc.d/init.d/mysqld 

[root@localhost mysql-5.0.18]# chmod 755 /etc/rc.d/init.d/mysqld  

把mysqld添加到chkconfig中 

[root@localhost mysql-5.0.18]# chkconfig --add mysqld 

在圖形和字符集界面下自動啓動mysqld 

[root@localhost mysql-5.0.18]# chkconfig --level 3 mysqld on 

[root@localhost mysql-5.0.18]# chkconfig --level 5 mysqld on

再使用chkconfig --list命令檢查設置 [root@localhost mysql-5.0.18]# chkconfig --list mysqld mysqld          0:off   1:off   2:on    3:on    4:off    5:on    6:off 

相關文章
相關標籤/搜索