mysql官方網站:http://dev.mysql.com/downloads/mysql
Linux環境:剛安裝的32位的「最小化安裝「的CentOS 6.7linux
mysql版本:本次實驗安裝的是mysql5.1,基於32位操做系統,這次下載的爲二進制免編譯包。安裝環境爲32位CentOS 6.7sql
搜狐開源鏡像站點:http://mirrors.sohu.com/,去這兒下載mysql源碼包。
數據庫
一.安裝mysql vim
卸載centos自帶的mysql:centos
[root@huh ~]# which mysql /usr/bin/mysql [root@huh ~]# rpm -qf /usr/bin/mysql mysql-5.1.73-5.el6_6.i686 [root@huh ~]# yum remove mysql
安裝mysql:緩存
[root@huh ~]# cd /usr/local/src/ [root@huh src]# wget http://mirrors.sohu.com/mysql/MySQL-5.1/mysql-5.1.73-linux-i686-glibc23.tar.gz
[root@huh src]# tar -zxvf mysql-5.1.73-linux-i686-glibc23.tar.gz [root@huh src]# mv mysql-5.1.73-linux-i686-glibc23 /usr/local/mysql/
注:咱們將mysql安裝在/usr/local/mysql/目錄下併發
添加mysql軟連接:socket
[root@huh ~]# ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
二.創建mysql用戶,並初始化數據庫tcp
[root@huh src]# useradd -s /sbin/nologin -M mysql [root@huh src]# cd /usr/local/mysql [root@huh mysql]# mkdir -p /data/mysql [root@huh mysql]# chown -R mysql /data/mysql [root@huh mysql]# /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
注:1.建立的mysql用戶不能登陸終端,沒有建立家目錄
2.mkdir的參數-p表示級聯建立
3.將/data/mysql目錄的屬組改成mysql
4.mysql_install_db用來初始化數據庫,--user定義數據庫的所屬主,--datadir定義數據庫安裝到哪裏。(若出現兩個OK表明初始化成功)
三.拷貝配置文件my.cnf和啓動腳本mysqld
拷貝配置文件並修改:
[root@huh mysql]# cd support-files/ [root@huh support-files]# cp my-large.cnf /etc/my.cnf
[root@huh support-files]# vim /etc/my.cnf
並將my.cnf中的"log-bin=mysql-bin"和"binlog_format=mixed"這兩個配置行註釋掉
拷貝啓動腳本並修改:
[root@huh support-files]# cp mysql.server /etc/init.d/mysqld
[root@huh support-files]# chmod 755 /etc/init.d/mysqld
[root@huh support-files]# vim /etc/init.d/mysqld
找到"basedir="和"datadir="這兩個配置行,並改成"basedir=/usr/local/mysql"和"datadir=/data/mysql"
注:1.mysqld腳本文件中basedir指定咱們的mysql程序放在哪,
2.mysqld腳本文件中datadir指定咱們定義的data mysql。
四.將mysql加入系統服務並啓動
[root@huh support-files]# chkconfig --add mysqld [root@huh support-files]# chkconfig mysqld on [root@huh support-files]# /etc/init.d/mysqld start Starting MySQL [肯定]
注:chkconfig是檢查和設置系統的各類服務
五.查看mysql進程和監聽端口:
[root@huh support-files]# ps aux |grep mysql root 1952 0.0 0.1 6680 1340 pts/0 S 03:30 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/huh.pid mysql 2070 0.2 4.3 390556 44592 pts/0 Sl 03:30 0:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --user=mysql --log-error=/data/mysql/huh.err --pid-file=/data/mysql/huh.pid --socket=/tmp/mysql.sock --port=3306 root 2090 0.0 0.0 6048 780 pts/0 R+ 03:31 0:00 grep --color mysql [root@huh support-files]# netstat -lnp |grep mysql tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 2070/mysqld unix 2 [ ACC ] STREAM LISTENING 22354 2070/mysqld /tmp/mysql.sock
六.mysql配置文件講解
過濾掉註釋信息後的/etc/my.cnf的文件內容:
#my.cnf [client] port= 3306 socket= /tmp/mysql.sock #The mysql server [mysqld] port= 3306 #端口 socket= /tmp/mysql.sock #監聽的socket skip-locking #是否要過濾掉lock key_buffer_size = 256M #用戶索引塊的緩衝區,增長它能夠得到更好的索引處理速度 max_allowed_packet = 1M #容許最大的包 table_open_cache = 256 #全部線程打開表的數量 sort_buffer_size = 1M #排序的緩衝區內存大小(一個線程) read_buffer_size = 1M #讀的緩衝區 read_rnd_buffer_size = 4M #隨機讀的緩衝區 myisam_sort_buffer_size = 64M #針對myisam引擎來講的 thread_cache_size = 8 #緩存可重用的限制,跟cpu核數有關 query_cache_size= 16M #查詢緩存 thread_concurrency = 8 #和cpu核數有關,最大併發線程數 log-bin=mysql-bin binlog_format=mixed server-id= 1 [mysqldump] quick max_allowed_packet = 16M [mysql] no-auto-rehash [myisamchk] key_buffer_size = 128M sort_buffer_size = 128M read_buffer = 2M write_buffer = 2M [mysqlhotcopy] interactive-timeout
附:
1.mysql禁止監聽端口:在/etc/my.cnf中mysqld配置部分加入一行skip-networking,重啓mysql便可