您好,登錄后才能下訂單哦!
不知道大家之前對類似MySQL5.6編譯安裝及配置數據庫教程的文章有無了解,今天我在這里給大家再簡單的講講。感興趣的話就一起來看看正文部分吧,相信看完MySQL5.6編譯安裝及配置數據庫教程你一定會有所收獲的。
編譯安裝:
創建MySQL專用賬戶和用戶組:
groupaddmysql
useradd-g mysql mysql
設置用戶操作系統資源的限制,在/etc/security/limits.conf最后添加
mysql soft nproc 2047
mysql hardnproc 16384
mysql soft nofile 1024
mysql hardnofile 65536
執行cmake . -LAH查看MySQL編譯所有支持的參數,或者通過http://dev/mysql.com/doc/refman/5.6/en/source-configuration-options.html查看官方技術文檔
安裝cmake:
yuminstall cmake
出現問題:Generic Linux (Architecture Independent), Compressed TAR Archive
解決:yum -y install ncurses-devel
出現問題:CMAKE_C_COMPILER not set, after EnableLanguage
解決:yum install gcc-c++
rm -f CMakeCache.txt
重新編譯安裝
解壓源碼包:tar -zvfx mysql-5.6.28.tar.gz
進入解壓目錄,執行cmake編譯并安裝:
cdmysql-5.6.28
cmake. -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_COLLATION=utf8_general_ci-DDEFAULT_CHARSET=utf8 -DENABLED_LOCAL_INFILE=ON-DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1-DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1-DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 -DCOMPILATION_COMMENT='JSSfor mysqltest' -DWITH_READLINE=ON -DSYSCONFDIR=/data/mysqldata/3306-DMYSQL_UNIX_ADDR=/data/mysqldata/3306/mysql.sock
make && make install
修改軟件所在目錄擁有者為mysql:
chown-R mysql:mysql /usr/local/mysql
修改mysql用戶環境變量,在/home/mysql/.bash_profile添加
# exportLANG=zh_CN.GB18030
exportPATH=/usr/local/mysql/bin:$PATH
管理MySQL數據庫服務
MySQL數據庫服務:MySQL軟件、MySQL實例和MySQL數據庫幾部分的總稱
MySQL實例:指MySQL進程以及該進程持有的內存資源
MySQL數據庫:MySQLdata目錄或MySQLdatabase文件
mysql數據庫:mysql這個DB
mysql:連接MySQL數據庫的命令行方式交互工具mysql
創建數據庫文件默認路徑:
mkdir -p/data/mysqldata/{3306/{data,tmp,binlog},backup,scripts}
chown -R mysql:mysql /data/mysqldata
chown -R mysql:mysql /usr/local/mysql
添加MySQL配置文件/data/mysqldata/3306/my.cnf如下:
[client]
port = 3306
socket = /data/mysqldata/3306/mysql.sock
# The MySQL server
[mysqld]
port = 3306
user = mysql
socket = /data/mysqldata/3306/mysql.sock
pid-file = /data/mysqldata/3306/mysql.pid
basedir = /usr/local/mysql
datadir = /data/mysqldata/3306/data
tmpdir = /data/mysqldata/3306/tmp
open_files_limit = 10240
explicit_defaults_for_timestamp
sql_mode =NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
# Buffer
max_allowed_packet = 256M
max_heap_table_size = 256M
net_buffer_length = 8K
sort_buffer_size = 2M
join_buffer_size = 4M
read_buffer_size = 2M
read_rnd_buffer_size = 16M
# Log
log-bin =/data/mysqldata/3306/binlog/mysql-bin
binlog_cache_size = 32m
max_binlog_cache_size = 512m
max_binlog_size = 512m
binlog_format = mixed
log_output = FILE
log-error = ../mysql-error.log
slow_query_log = 1
slow_query_log_file = ../slow_query.log
general_log = 0
general_log_file = ../general_query.log
expire-logs-days = 14
# InnoDB
innodb_data_file_path = ibdata1:2048M:autoextend
innodb_log_file_size = 256M
innodb_log_files_in_group = 3
innodb_buffer_pool_size = 1024M
[mysql]
no-auto-rehash
prompt = (\u@\h) [\d]\_
default-character-set = gbk
初始化MySQL數據庫:
/usr/local/mysql/scripts/mysql_install_db--datadir=/data/mysqldata/3306/data --basedir=/usr/local/mysql
啟動MySQL服務:
$ /usr/local/mysql/bin/mysqld_safe--defaults-file=/data/mysqldata/3306/my.cnf &
連接數據庫:
$ /usr/local/mysql/bin/mysql
檢查MySQL服務是否啟動:
netstat -tnl | grep 3306
保留一條允許root用戶從本地連接的記錄外,刪除全部其他用戶:
delete from mysql.user where (user,host)not in (select 'root','localhost');
修改管理員用戶:
update mysql.user setuser='system',password=password('password');
truncate table mysql.db;
生效所有操作:
flush privileges;
MySQL服務管理配置
創建中間定義文件,提高腳本的復用性:
$ vi/data/mysqldata/scripts/mysql_env.ini
# set env
MYSQL_USER=system
MYSQL_PASS=’password’
# check parameter
if [ $# -ne 1 ]
then
HOST_PORT=3306
else
HOST_PORT=$1
fi
修改該文件在操作系統層的權限:
$ chmod 600/data/mysqldata/scripts/mysql_env.ini
創建mysql_db_startup.sh腳本,用于啟動MySQL服務:
$ vi/data/mysqldata/scripts/mysql_db_startup.sh
#!/bin/sh
source/data/mysqldata/scripts/mysql_env.ini
echo "Stratup MySQL Service:local_"${HOST_PORT}
/usr/local/mysql/bin/mysqld_safe--defaults-file=/data/mysqldata/${HOST_PORT}/my.cnf &
創建mysql_db_shutdown.sh腳本,用于關閉MySQL服務:
$ vi /data/mysqldata/scripts/mysql_db_shutdown.sh
#!/bin/sh
source/data/mysqldata/scripts/mysql_env.ini
echo "Shutdown MySQL Service:localhost_"${HOST_PORT}
/usr/local/mysqldata/bin/mysqladmin-u${MYSQL_USER} -p${MYSQL_PASS} -S /data/mysqldata/${HOST_PORT}/mysql.sockshutdown
創建mysqlplus.sh腳本文件用于快速登錄:
$ vi/data/mysqldata/scripts/mysqlplus.sh
#!/bin/sh
source/data/mysqldata/scripts/mysql_env.ini
echo "Login MySQL Service:localhost_"${HOST_PORT}
/usr/local/mysql/bin/mysql-u${MYSQL_USER} -p${MYSQL_PASS} -S /data/mysqldata/${HOST_PORT}/mysql.sock $2
授權以上腳本執行權限:
$ chmod +x /data/mysqldata/scripts/*.sh
編輯mysql用戶的環境變量,將上述路徑加入到PATH中:
$ echo "exportPATH=/data/mysqldata/scripts:$PATH">>~/.bash_profile
$ source ~/.bash_profile
編輯/etc/rc.local使MySQL開機啟動,在最后添加:
sudo -i -u mysql/data/mysqldata/scripts/mysql_db_startupsh 3306 >/home/mysql/mysql_db_startup.log 2>&1
visudo把Defaultsrequiretty注釋掉,避免sudo: sorry,you myst have a ttyto run sudo
看完MySQL5.6編譯安裝及配置數據庫教程這篇文章,大家覺得怎么樣?如果想要了解更多相關,可以繼續關注我們的行業資訊板塊。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。