AliSQL-5.6.32編譯安裝
2、需要的軟件mirrors-alisql-master.zip 以及需要的依賴包centos-release-scl devtoolset-4-gcc-c++ devtoolset-4-gcc ncurses-devel openssl-devel bison git cmake
3、安裝需要的依賴軟件包
yum -y install centos-release-scl devtoolset-4-gcc-c++ devtoolset-4-gcc ncurses-devel openssl-devel bison git cmake
4、下載 mirrors-alisql-master.zip
https://github.com/alibaba/AliSQL
5、解壓mirrors-alisql-master.zip
unzip mirrors-alisql-master.zip
6、創建Mysql用戶組和用戶,及數據庫存放目錄:
mkdir -p /usr/local/mysql
mkdir -p /usr/local/mysql/tmp
mkdir -p /var/log/mysql
groupadd mysql
useradd mysql -g mysql -M -s /sbin/nologin
chown -R mysql.mysql /usr/local/mysql
chown -R mysql.mysql /var/log/mysql
7、編譯安裝
cd alisql
cmake . \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DCMAKE_BUILD_TYPE="Release" \
-DWITH_EMBEDDED_SERVER=0 \
-DWITH_EXTRA_CHARSETS=all \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_CSV_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DWITH_TOKUDB_STORAGE_ENGINE=0 \
-DENABLE_DTRACE=0 \
-DENABLED_LOCAL_INFILE=1 \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci \
-DEXTRA_CHARSETS=all \
-DMYSQL_USER=mysql \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DENABLE_DOWNLOADS=1 \
-DWITH_DEBUG=OFF \
-DENABLED_PROFILING=ON \
-DMYSQL_MAINTAINER_MODE=OFF
scl enable devtoolset-4 bash #在配置前,要先設置下環境變量,這樣才能用到 devtoolset-4 套裝裏的gcc
make -j4 && make install #-j4 表示開 4 個並發編譯進程,加速編譯,根據機器 CPU 核數調整,一般是 CPU 核數 + 1
8、編輯配置文件
[client]
port = 3306
socket = /usr/local/mysql/mysql.sock
default-character-set = utf8mb4
[mysql]
prompt="AliSQL [\d]> "
#no-auto-rehash
[mysqld]
port = 3306
user = mysql
skip-name-resolve
socket = /usr/local/mysql/mysql.sock
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
pid-file = /usr/local/mysql/mysql.pid
tmpdir = /usr/local/mysql/tmp
slave-load-tmpdir = /usr/local/mysql/tmp
log_error = /var/log/mysql/mysqld.log
#secure-file-priv = /usr/local/mysql/uploads
#慢查詢
slow_query_log = 1
long_query_time = 2
log-queries-not-using-indexes
slow_query_log_file = /var/log/mysql/mysql_slow.log
log-slow-admin-statements = 1
log-slow-slave-statements = 1
log-bin-trust-function-creators = 1
#init-connect = ‘SET NAMES utf8‘
#character-set-server = utf8
init-connect = ‘SET NAMES utf8mb4‘
character-set-server = utf8mb4
symbolic-links = 0
#lower_case_table_names = 1
performance_schema = 0
#bind-address = 0.0.0.0
#開啟查詢緩存
explicit_defaults_for_timestamp=true
#消耗系統IO 內存等
#log-output = FILE
#general_log = off
#general_log_file = /var/log/mysql/general.log
##^^^^^^^^^^^^^^^^^^^^^^主從同步相關設置開始^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^##
server-id = 10
binlog_cache_size = 4M
max_binlog_size = 1G
max-binlog-cache-size = 2G
max-relay-log-size = 1G
log_bin = /var/log/mysql/mysql-master-bin
binlog_format = mixed
log_bin_index = /var/log/mysql/bin_log.index
expire_logs_days = 90
#skip-locking
#禁止外網
#skip-networking
#禁止域名解析
skip-name-resolve
#skip-grant-tables
#禁止鎖定
skip-external-locking
skip_show_database
skip_symbolic_links
back_log = 300
max_connections = 1000
max_connect_errors = 6000
open_files_limit = 65535
#表緩存數
table_open_cache = 128
binlog_cache_size = 1M
#最大表量
max_heap_table_size = 256M
tmp_table_size = 16M
#根據物理內存設置規則如下:1G=8 ; 2G=16; 3G=32; 3G>= =64
thread_cache_size = 16
open-files-limit=8192
#排序緩沖
sort_buffer_size=256M
#啟動高速緩存
query_cache_type = 1
#查詢緩存 很少有相同的查詢,最好不要使用查詢緩存
query_cache_size = 128M
query_cache_limit = 2M
flush_time = 0
#連續緩沖
join_buffer_size = 16M
group_concat_max_len=2048000
table_definition_cache = 1400
ft_min_word_len = 4
#預讀緩沖
read_buffer_size = 2M
#次緩沖
read_rnd_buffer_size = 64M
query_cache_min_res_unit = 1MB
bulk_insert_buffer_size = 8M
#索引緩沖 比較理想的設置:Key_blocks_used / (Key_blocks_unused + Key_blocks_used) * 100% ≈ 80%
key_buffer_size=64M
#default-storage-engine = MyISAM
default_storage_engine = InnoDB
innodb_file_per_table = 1
innodb_open_files = 500
#參數的配置在物理內存的70%-80%之間
innodb_buffer_pool_size = 64M
#InnoDB 使用後臺線程處理數據頁上寫 I/O(輸入)請求的數量
innodb_write_io_threads = 4
#InnoDB 使用後臺線程處理數據頁上讀 I/O(輸出)請求的數量
innodb_read_io_threads = 4
innodb_thread_concurrency = 0
innodb_purge_threads = 1
innodb_flush_log_at_trx_commit = 2
#日誌緩沖池,控制在8M-16M即可
innodb_log_buffer_size = 2M
#InnoDB 日誌文件的大小
innodb_log_file_size = 256M
innodb_log_files_in_group = 3
#控制了 Dirty Page 在 Buffer Pool 中所占的比率
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
#緩沖區刷新到磁盤時,刷新臟頁數量,ssd磁盤,或做了raid後,可將此值設置較大
innodb_io_capacity = 200
innodb_adaptive_flushing = OFF
innodb_autoextend_increment = 64
innodb_buffer_pool_instances = 8
innodb_concurrency_tickets = 5000
innodb_old_blocks_time = 1000
innodb_stats_on_metadata = 0
myisam_sort_buffer_size = 16M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
#導入大的sql文件的方法
interactive_timeout = 28800
wait_timeout = 28800
connect_timeout = 20
#單數據包
max_allowed_packet = 500M
#thread_concurrency = 8
[mysqlhotcopy]
interactive-timeout
[mysqldump]
quick
max_allowed_packet = 500M
[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M
[mysqld_safe]
log_error = /var/log/mysql/mysqld.log
pid-file = /usr/local/mysql/mysql.pid
chown mysql.mysql /etc/my.cnf
chmod 600 /etc/my.cnf
9、初始化數據庫:(初始化的時候要註意,會生成一個root的隨機密碼,後面登錄會用到)
chmod 777 scripts/mysql_install_db
scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql --defaults-file=/etc/my.cnf
10、設置環境變量
vim /etc/profile
export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib
11、復制 mysql 服務啟動配置文件
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod a+x /etc/init.d/mysqld
12、啟動數據庫進程
service mysqld start
13、修改root密碼,設置遠程登錄
mysql -u root
AliSQL [mysql]>use mysql;
AliSQL [mysql]>select host, user from user;
AliSQL [mysql]>update user set password=PASSWORD(‘rootoo‘)where user=‘root‘;
AliSQL [mysql]>update user set host = ‘%‘ where user = ‘root‘; #授權遠程登錄用戶名為root,如果報錯,ERROR 1062 (23000): Duplicate entry ‘%-root‘ for key ‘PRIMARY‘,不予理會
AliSQL [mysql]>flush privileges;
AliSQL [mysql]>grant all on . to "root"@"172.30.41.72" identified by "123456"; #授權172.30.41.72以root用戶遠程登錄訪問數據庫,root密碼為123456
AliSQL [mysql]>grant all on . to "root"@"%" identified by "123456"; #授權所有ip都可以以root用戶遠程登錄訪問數據庫,root密碼為123456
AliSQL [mysql]>grant all on . to "root"@"localhost" identified by "123456"; #授權localhost以root用戶遠程登錄訪問數據庫,root密碼為123456
AliSQL [mysql]>select user from user; #查看所有用戶
14、重啟mysql
service mysqld restart
chkconfig mysqld on
15、下載phpMyAdmin
wget https://files.phpmyadmin.net/phpMyAdmin/4.7.0/phpMyAdmin-4.7.0-all-languages.zip
16、解壓phpMyAdmin-4.7.0-all-languages.zip
unzip phpMyAdmin-4.7.0-all-languages.zip
17、打開libraries下的config.default.php文件,依次找到下面各項,按照說明配置即可:
a.訪問網址
$cfg[‘pmaabsoluteuri‘] = ‘192.168.1.5‘;這裏填寫phpmyadmin的訪問網址
b.mysql主機信息
$cfg[‘servers‘][$i][‘host‘] = ‘localhost‘; // mysql hostname or ip address
填寫localhost或mysql所在服務器的ip地址,如果mysql和該phpmyadmin在同一服務器,則按默認localhost
$cfg[‘servers‘][$i][‘port‘] = ‘‘; // mysql port - leave blank for default port
mysql端口,如果是默認3306,保留為空即可
c.mysql用戶名和密碼
$cfg[‘servers‘][$i][‘user‘] = ‘root‘; // mysql user訪問phpmyadmin使用的mysql用戶名
fg[‘servers‘][$i][‘password‘] = ‘rootoo‘; // mysql password (only needed對應上述mysql用戶名的密碼
d.認證方法
$cfg[‘servers‘][$i][‘auth_type‘] = ‘http‘;
在此有四種模式可供選擇,cookie,http,http,config
config方式即輸入phpmyadmin的訪問網址即可直接進入,無需輸入用戶名和密碼,是不安全的,不推薦使用。
當該項設置為cookie,http或http時,登錄phpmyadmin需要數據用戶名和密碼進行驗證,,具體如下:
php安裝模式為nginx/apache,可以使用http和cookie;
php安裝模式為cgi,可以使用cookie
e.短語密碼(blowfish_secret)的設置
$cfg[‘blowfish_secret‘] = ‘‘;
如果認證方法設置為cookie,就需要設置短語密碼,但是不能留空,否則會在登錄phpmyadmin時提示錯誤
f.配置
1、打開 /libraries/config.default.php文件(舊版本是根目錄下的config.inc.php文件),用寫字板(不要用記事本,這是utf8編碼)進行編輯,按照說明配置即可。
2、查找 $cfg[‘pmaabsoluteuri‘]=‘‘; // 修改為你將上傳到空間的phpmyadmin的網址
如:$cfg[‘pmaabsoluteuri‘] =‘http: // 網站域名/phpmyadmin/‘;
3、查找 $cfg[‘servers‘][$i][‘host‘] =‘localhost‘; // 通常用默認,也有例外,可以不用修改
4、查找 $cfg[‘servers‘][$i][‘auth_type‘] =‘config‘; // 在自己的機子裏調試用config;如果在網絡上的空間用cookie.
18、http://192.168.1.5/phpMyAdmin/ 輸入用戶名root密碼rootoo後,訪問正常
常見的錯誤:#2002 - Permission denied — 服務器沒有響應(或本地服務器的套接字沒有正確設置)。
報錯原因:如果未指定指定主機名或指定了特殊的主機名localhost,將使用Unix套接字。
Unix套接字默認為/tmp/mysql.sock,如果沒有配置這樣的套接字文件或者配置不正確,所以自然是連接失敗了。
解決方法:$cfg[‘servers‘][$i][‘host‘] =‘localhost‘;改為$cfg[‘servers‘][$i][‘host‘] =‘127.0.0.1‘;
AliSQL-5.6.32編譯安裝