標籤:blog http os strong 檔案 資料 io 2014
一.線上安裝
yum list | grep mysql
顯示yum伺服器上mysql的版本資訊
通過如下命令進行安裝:
yum install -y mysql-server mysql mysql-devel
安裝完成後通過如下命令進行查看安裝的版本號碼
rpm -qi mysql-server
伺服器的相關配置
service mysqld start #開啟伺服器
service mysqld restart #重啟伺服器
service mysqld stop #關閉伺服器
chkconfig --list | grep mysqld #查看mysqld是否開機啟動
chkconfig mysqld on #設定開機啟動mysql
mysqladmin -u root password ‘root‘ # 通過該命令給root帳號設定密碼為 root
mysql -u root -p #登陸資料庫
/etc/my.cnf 這是mysql的主設定檔
/var/lib/mysql mysql資料庫的資料庫檔案存放位置
二、源碼編譯安裝
1、下載安裝編譯MySQL源碼需要的庫
sudo apt-get install build-essential libncurses5-dev cmake
2、添加mysql使用者組和使用者
groupadd mysql
useradd -g mysql mysql
3、建立MySQL軟體安裝目錄和資料存放目錄
mkdir -p /opt/mysql #MySQL安裝目錄
chown -R mysql:mysql /opt/mysql
mkdir -p /data/mysql #MySQL資料存放目錄
mkdir -p /data/mysql/data #存放資料
mkdir -p /data/mysql/log #存放日誌
mkdir -p /data/mysql/tmp #存放臨時檔案
chown -R mysql:mysql /data/mysql
4、cmake編譯安裝MySQL
tar -zxvf mysql-5.6.13.tar.gz
cd mysql-5.6.13
cmake . -DCMAKE_INSTALL_PREFIX=/opt/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/opt/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DENABLED_LOCAL_INFILE=1
make
make install
參數說明:
-DCMAKE_INSTALL_PREFIX=/opt/mysql //指定安裝目錄
-DINSTALL_DATADIR=/data/mysql //指定資料存放目錄
-DSYSCONFDIR=/opt/mysql //指定設定檔目錄(本例的設定檔為/opt/mysql/my.cnf)
-DDEFAULT_CHARSET=utf8 //指定字元集
-DDEFAULT_COLLATION=utf8_general_ci //指定校正字元
-DEXTRA_CHARSETS=all //安裝所有擴充字元集
-DENABLED_LOCAL_INFILE=1 //允許從本地匯入資料
上述步驟執行成功後,MySQL軟體已成功安裝至/opt/mysql目錄下。
5、編輯設定檔my.cnf
[client]
port= 3306
socket = /opt/mysql/run/mysql.sock
[mysql]
[mysqld_safe]
pid-file = /opt/mysql/run/mysqld.pid
socket = /opt/mysql/run/mysql.sock
nice= 0
[mysqld]
#### Baes dir ####
basedir = /opt/mysql
datadir = /data/mysql/data
tmpdir = /data/mysql/tmp
socket = /opt/mysql/run/mysql.sock
user=mysql
#### Base configure info ####
port = 3306
skip-external-locking
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address= 127.0.0.1
#
# * Fine Tuning
#
key_buffer= 16M
max_allowed_packet= 16M
thread_stack= 192K
thread_cache_size = 8
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover = BACKUP
#max_connections = 100
#table_cache = 64
#thread_concurrency = 10
#
# * Query Cache Configuration
#
query_cache_limit= 1M
query_cache_size = 16M
#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
# As of 5.1 you can enable the log at runtime!
#general_log_file = /var/log/mysql/mysql.log
#general_log = 1
log-error = /data/mysql/log/alert.log
slow_query_log_file= /data/mysql/log/slow.log
# Here you can see queries with especially long duration
#log_slow_queries= /var/log/mysql/mysql-slow.log
#long_query_time = 2
#log-queries-not-using-indexes
#### Binary log && Relay log ####
#binlog_format=‘MIXED‘
log-bin = /data/mysql/log/mysql-bin
log-slave-updates = 1
relay-log = /data/mysql/log/mysqld-relay-bin
relay-log-index = /data/mysql/log/mysqld-relay-bin.index
master-info-file = /data/mysql/log/master.info
relay-log-info-file = /data/mysql/log/relay-log.info
max_binlog_size = 100M
[mysqldump]
quick
quote-names
max_allowed_packet= 16M
[mysql]
#no-auto-rehash# faster start of mysql but no tab completition
[isamchk]
key_buffer= 16M
6、建立資料庫
/opt/mysql/scripts/mysql_install_db --user=mysql --explicit_defaults_for_timestamp --basedir=/opt/mysql/
上述建庫語句將根據my.cnf裡設定的資料檔案目錄和記錄檔目錄,產生相應的資料檔案和記錄檔,並建立系統資料庫(如mysql,test,information_schema,performance_schema)
7、啟動MySQL
/opt/mysql/support-files/mysql.server start
啟動成功後,就可以以root使用者登入(預設的root使用者沒有密碼)
/opt/mysql/bin/mysql -u root
查看是否可以登入
8、設定root密碼
mysqladmin -u root password ‘123456a?‘
mysql -uroot -p
GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘%‘ IDENTIFIED BY ‘123456a?‘ WITH GRANT OPTION;
9、最後,把MySQL加入系統啟動項和開機啟動
在/etc/profile 檔案中增加
export PATH=$PATH:/opt/mysql/bin
cp ./support-files/mysql.server /etc/init.d/mysqld #把Mysql加入系統啟動
chmod 755 /etc/init.d/mysqld #增加執行許可權
update-rc.d -f mysqld defaults #加入開機啟動