原創作品,允許轉載,轉載時請務必以超鏈接形式標明文章 原始出處 、作者信息和本聲明。否則將追究法律責任。http://nolinux.blog.51cto.com/4824967/1321079
MySQL是一個關系型數據庫管理系統,由瑞典MySQL AB公司開發,目前屬于Oracle公司。MySQL所使用的SQL語言是用于訪問數據庫的最常用標準化語言。由于其體積小、速度快、總體擁有成本低,尤其是開放源碼這一特點,一般中小型網站的開發都選擇MySQL作為網站數據庫。由于其社區版的性能卓越,搭配PHP和Apache可組成良好的開發環境。本篇將為大家講解mysql的簡單部署。
Alpha版:一般只在軟件開發公司內部運行,不對外公開。 Beta版:完成功能的開發和所有的測試工作之后的產品,不會存在較大的漏洞和BUG,并且邀請和提供給用戶體驗與測試,以便更全面地測試軟件的不足之處或存在的問題。 RC版:屬于生產環境發布之前的一個小版本或稱候選版本,是測試Beta版本二收集到的BUG或不足之處,根據手機到的信息而進行修復和完善之后的產品。 GA版本:軟件產品正式發布的版本,也成生產版本的產品。
第一條產品線:從5.0版本升級到5.1的系列版本,繼續完善與改進其用戶體驗和性能,同時增加新功能。 第二條產品線:為了更好的整合MySQL AB公司,社區和新功能。版本編號從5.4開始,目前發展到5.6。 第三條產品線:為了更好推廣MySQL Cluster 版本,從6.0版本開始,目前發展到7.3版本。
環境 CentOS6.4 x86_64位 采用最小化安裝,系統經過了基本優化 selinux為關閉狀態,iptables為無限制模式 ip:192.168.1.113/24 mysql版本:mysql-5.1.70 源碼包存放位置:/server/tools 源碼包編譯安裝位置:/etc/local/軟件名稱 數據庫存放位置:/mydata
[root@c64-web ~]# yum groupinstall "Development tools" "Server Platform Development" -y #安裝這兩個開發環境的軟件包組 [root@c64-web ~]# yum install pcre* -y #安裝pcre兼容的正則表達式
[root@c64-web ~]# useradd -s /sbin/nologin -M mysql #創建mysql用戶,并加入mysql組,不創建家目錄,關閉登陸 [root@c64-web ~]# mkdir /mydata #創建數據庫存放目錄 [root@c64-web ~]# chown -R mysql.mysql /mydata
[root@c64-web ~]# cd /server/tools [root@c64-web tools]# wget http://mysql.ntu.edu.tw/Downloads/MySQL-5.1/mysql-5.1.70.tar.gz
[root@c64-web tools]# tar zxf mysql-5.1.70.tar.gz [root@c64-web tools]# cd mysql-5.1.70 [root@c64-web mysql-5.1.70]# ./configure \ --prefix=/usr/local/mysql \ #設定mysql安裝路徑,默認為/usr/local --with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock \ #指定Mysql socket文件存放目錄 --localstatedir=/mydata \ #設定mysql的數據文件存放位置 --enable-assembler \ #允許使用匯編模式(優化性能) --enable-thread-safe-client \ #以線程方式編譯客戶端 --with-mysqld-user=mysql \ #指定MySQL運行的系統用戶 --with-big-tables \ #啟用大表支持 --without-debug \ #使用非debug模式 --with-pthread \ #強制使用pthread線程序庫編譯 --with-extra-charsets=complex \ #復雜字符集支持 --with-readline \ #使用系統readline代替捆綁副本。 --with-ssl \ #啟用ssl加密 --with-embedded-server \ #構建嵌入式MySQL庫 (libmysqld.a) --enable-local-infile \ #讓mysql支持從本地加載數據庫(默認關閉) --with-plugins=partition #mysql分區功能支持 --with-plugins=innobase \ #innobas存儲引擎支持 --with-mysqld-ldflags=-all-static \ #服務器使用靜態庫(優化性能) --with-client-ldflags=-all-static #客戶端使用靜態庫(優化性能) [root@c64-web mysql-5.1.70]# make && make install
[root@c64-web mysql-5.1.70]# ./configure –prefix=/usr/local/mysql-5.1.70 –with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock –localstatedir=/mydata –enable-assembler –enable-thread-safe-client –with-mysqld-user=mysql –with-big-tables –without-debug –with-pthread –with-extra-charsets=complex –with-readline –with-ssl –with-embedded-server –enable-local-infile –with-plugins=partition –with-plugins=innobase –with-mysqld-ldflags=-all-static –with-client-ldflags=-all-static
[root@c64-web mysql-5.1.70]# cd /root [root@c64-web ~]# ln -s /usr/local/mysql-5.1.70 /usr/local/mysql
[root@c64-web ~]# mkdir /mydata #建立mysql數據文件目錄 [root@c64-web ~]# chown -R mysql /mydata #授權mysql用戶訪問mysql數據庫目錄
[root@c64-web ~]# ll /server/tools/mysql-5.1.70/support-files/*.cnf -rw-r--r-- 1 root root 4714 11月 6 02:25 /server/tools/mysql-5.1.70/support-files/my-huge.cnf -rw-r--r-- 1 root root 19763 11月 6 02:25 /server/tools/mysql-5.1.70/support-files/my-innodb-heavy-4G.cnf -rw-r--r-- 1 root root 4688 11月 6 02:25 /server/tools/mysql-5.1.70/support-files/my-large.cnf -rw-r--r-- 1 root root 4699 11月 6 02:25 /server/tools/mysql-5.1.70/support-files/my-medium.cnf -rw-r--r-- 1 root root 2467 11月 6 02:25 /server/tools/mysql-5.1.70/support-files/my-small.cnf #中小型公司用這個即可 [root@c64-web mysql-5.1.70]# /bin/cp /server/tools/mysql-5.1.70/support-files/my-small.cnf /etc/my.cnf 修改mysql的主配置文件/etc/my.cnf,添加如下1行 datadir=/mydata #我們自定義的數據庫存放目錄
[root@c64-web ~]# ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql
[root@c64-web ~]# echo "/usr/local/mysql/lib" >> /etc/ld.so.conf.d/mysql.conf [root@c64-web ~]# ldconfig
[root@c64-web ~]# ln -s /usr/local/mysql/include/mysql /usr/include/mysql
[root@c64-web ~]# echo "PATH=/usr/local/mysql/bin:$PATH" >>/etc/profile [root@c64-web ~]# source /etc/profil
[root@c64-web ~]# /usr/local/mysql/bin/mysql_install_db --basedir=/usr/local/mysql --datadir=/mydata --user=mysql #初始化mysql數據庫文件 WARNING: The host 'c64-web' could not be looked up with resolveip. This probably means that your libc libraries are not 100 % compatible with this binary MySQL version. The MySQL daemon, mysqld, should work normally with the exception that host name resolving will not work. This means that you should use IP addresses instead of hostnames when specifying MySQL privileges ! #此警告我們可以通過在/etc/hosts文件中修改127.0.0.1后面的localhost為當前c64-web來消除。 Installing MySQL system tables... 131108 18:07:26 [Warning] '--skip-locking' is deprecated and will be removed in a future release. Please use '--skip-external-locking' instead. #這里的警告無需理會 OK Filling help tables... 131108 18:07:27 [Warning] '--skip-locking' is deprecated and will be removed in a future release. Please use '--skip-external-locking' instead. #這里的警告無需理會 OK To start mysqld at boot time you have to copy support-files/mysql.server to the right place for your system #這里是說,你可以創建快速啟動腳本,我們下面會提到 PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! To do so, start the server, then issue the following commands: /usr/local/mysql/bin/mysqladmin -u root password 'new-password' /usr/local/mysql/bin/mysqladmin -u root -h lhh password 'new-password' #教你如何創建root用戶進入mysql數據庫的密碼 Alternatively you can run: /usr/local/mysql/bin/mysql_secure_installation which will also give you the option of removing the test databases and anonymous user created by default. This is strongly recommended for production servers. See the manual for more instructions. You can start the MySQL daemon with: cd /usr/local/mysql ; /usr/local/mysql/bin/mysqld_safe & #上面的即為開啟命令中的一種,后面的&為放入后臺執行的意思 You can test the MySQL daemon with mysql-test-run.pl cd /usr/local/mysql/mysql-test ; perl mysql-test-run.pl #這里是給你說如何執行測試 Please report any problems with the /usr/local/mysql/scripts/mysqlbug script! #以上為初始化創建mysql數據庫文件時產生的信息。 [root@lhh mydata]# cd /usr/local/mysql ; /usr/local/mysql/bin/mysqld_safe & [1] 7146 131108 18:50:37 mysqld_safe Logging to '/mydata/lhh.err'. 131108 18:50:37 mysqld_safe Starting mysqld daemon with databases from /mydata #此處需要敲擊回車才能回到命令輸入界面。
[root@c64-web ~]# /bin/cp /server/tools/mysql-5.1.70/support-files/mysql.server /etc/init.d/mysqld #拷貝mysql啟動腳本mysql命令路徑 [root@c64-web ~]# chmod 700 /etc/init.d/mysqld #使腳本可執行 [root@c64-web ~]# /etc/init.d/mysqld start #這是啟動數據庫方法之一 [root@c64-web ~]# /etc/init.d/mysqld stop #關閉數據庫的方法 [root@c64-web ~]# killalll mysqld #關閉數據庫的另外一種方法
[root@c64-web ~]# netstat -lnt|grep 3306 tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
[root@c64-web ~]# mysqladmin -u root password 123456 #設置密碼 [root@c64-web ~]# history -c #設置之后注意清除歷史記錄,防止密碼泄露 [root@c64-web ~]# mysql -u root -p #連接數據庫查看 Enter password: #這里輸入剛才設置的密碼 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.1.70 Source distribution Copyright (c) 2000, 2013, 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> show databases; #查看現有的數據庫 +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | test | +--------------------+ 3 rows in set (0.00 sec) mysql> select user(); #查看現有用戶 +----------------+ | user() | +----------------+ | root@localhost | +----------------+ 1 row in set (0.00 sec) mysql> quit #退出 Bye
[root@c64-web mysql-5.6.13]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ #指定mysql安裝目錄 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock \ #Unix socket文件路徑,自定義此路徑防報錯 -DDEFAULT_CHARSET=gbk \ #默認字符 -DDEFAULT_COLLATION=gbk_chinese_ci \ #校驗字符 -DEXTRA_CHARSETS=all \ #安裝所有擴展字符集 -DWITH_MYISAM_STORAGE_ENGINE=1 \ #安裝myisam存儲引擎 -DWITH_INNOBASE_STORAGE_ENGINE=1 \ #安裝innodb存儲引擎 -DWITH_ARCHIVE_STORAGE_ENGINE=1 \ #安裝archive存儲引擎 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ #安裝blackhole存儲引擎 -DWITH_MEMORY_STORAGE_ENGINE=1 \ #安裝memory存儲引擎 -DWITH_FEDERATED_STORAGE_ENGINE=1 #安裝frderated存儲引擎 -DWITH_READLINE=1 \ #快捷鍵功能 -DENABLED_LOCAL_INFILE=1 \ #允許從本地導入數據 -DMYSQL_DATADIR=/usr/local/mysql/data \ #數據庫存放目錄 -DMYSQL_USER=mysql \ #數據庫屬主 -DMYSQL_TCP_PORT=3306 \ #數據庫端口 -DSYSCONFDIR=/etc \ #MySQL配輯文件 -DWITH_SSL=yes #數據庫SSL
[root@c64-web mysql-5.6.13]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=gbk -DDEFAULT_COLLATION=gbk_chinese_ci -DEXTRA_CHARSETS=all -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/mydata -DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3306 -DSYSCONFDIR=/etc -DWITH_SSL=yes |
[root@c64-web mysql-5.6.13]# ll /server/tools/mysql-5.6.13/support-files/*.cnf -rw-r--r--. 1 root root 1126 Nov 8 01:37 /server/tools/mysql-5.6.13/support-files/my-default.cnf [root@c64-web mysql-5.6.13]# /bin/cp /server/tools/mysql-5.6.13/support-files/my-default.cnf /etc/my.cnf
轉自:http://nolinux.blog.51cto.com/4824967/1321079
原創文章,作者:s19930811,如若轉載,請注明出處:http://www.www58058.com/2009
好文章,內容文從字順.禁止此消息:nolinkok@163.com
好文章,內容一氣呵成.禁止此消息:nolinkok@163.com