MariaDB 在CentOS下的编译和安装
Eave
2015.12.03 18:23
1、安装编译依赖包
yum -y install cmake* gcc* c++ * autoconf automake zlib* libxml* ncurses-devel openssl-devel openssl libmcrypt* libtool-ltdl-deve libevent bison
2、下载MariaDB
https://downloads.mariadb.org/
3、编译安装MariaDB
useradd mysql
wget https://mirrors.tuna.tsinghua.edu.cn/mariadb//mariadb-10.3.8/source/mariadb-10.3.8.tar.gz
tar -zxf mariadb-10.3.8.tar.gz
cd mariadb-10.3.8
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DWITH_EXTRA_CHARSETS=complex -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DENABLED_PROFILING=on -DWITH_SSL=system -DWITH_ZLIB=system -DENABLED_THREAD_SAFE_CLIENT=on -DWITH_EMBEDDED_SERVER=on -DMYSQL_DATADIR=/usr/local/mysql/data -DMYSQL_USER=mysql -DMYSQL_UNIX_ADDR=/dev/shm/mysql.sock
make && make install
1.以mysql用户帐号的身份建立数据表
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
chmod +w /usr/local/mysql
chown -R mysql:mysql /usr/local/mysql
rm -f /usr/local/mysql/my.cnf
2.创建my.cnf配置文件
rm -f /etc/my.cnf
vi /etc/my.cnf
输入以下内容
[client]
port = 3306
socket = /dev/shm/mysql.sock
[mysqld]
character-set-server = utf8mb4
replicate-ignore-db = mysql
replicate-ignore-db = test
replicate-ignore-db = information_schema
user = mysql
bind-address = 127.0.0.1
port = 3306
socket = /dev/shm/mysql.sock
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
pid-file = /usr/local/mysql/data/mysql.pid
relay-log-index = /usr/local/mysql/relaylog/relaylog.index
relay-log-info-file = /usr/local/mysql/relaylog/relaylog.info
relay-log = /usr/local/mysql/relaylog/relaylog
log-error = /usr/local/mysql/data/mysql.err
open_files_limit = 10240
back_log = 600
max_connections = 5000
max_connect_errors = 6000
external-locking = FALSE
max_allowed_packet = 128M
sort_buffer_size = 10M
join_buffer_size = 10M
thread_cache_size = 512
query_cache_size = 512M
query_cache_limit = 20M
query_cache_min_res_unit = 512k
default-storage-engine = InnoDB
thread_stack = 192K
transaction_isolation = READ-COMMITTED
tmp_table_size = 512M
max_heap_table_size = 512M
long_query_time = 3
log-slave-updates
log-bin=mysql-bin
log-bin-index = mysql-bin.index
binlog_cache_size = 24M
binlog_format = MIXED
max_binlog_cache_size = 48M
max_binlog_size = 1G
expire_logs_days = 30
key_buffer_size = 512M
read_buffer_size = 10M
read_rnd_buffer_size = 64M
bulk_insert_buffer_size = 128M
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
myisam-recover-options
interactive_timeout = 1800
connect_timeout = 10
wait_timeout = 1800
skip-name-resolve
slave-skip-errors = 1032,1062,126,1114,1146,1048,1396
server-id = 1
thread_concurrency = 8
innodb_buffer_pool_size = 512M
innodb_data_file_path = ibdata1:10M:autoextend
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 16M
innodb_log_file_size = 128M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
innodb_file_per_table = 1
slow_query_log = on
slow-query-log-file = /usr/local/mysql/data/slow-query.log
long_query_time = 1 # 单位是秒
log-queries-not-using-indexes
sql-mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
[mysqldump]
quick
max_allowed_packet = 32M
3.启动MariaDB
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
service mysqld start
4.通过命令行登录管理MariaDB服务器(提示输入密码时直接回车)
/usr/local/mysql/bin/mysql -uroot -p
5.输入以下SQL语句,设置root用户的密码
MariaDB [(none)]> SET PASSWORD FOR 'root'@'127.0.0.1' = PASSWORD('123456');
MariaDB [(none)]> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123456');
MariaDB [(none)]> SET PASSWORD FOR 'root'@'::1' = PASSWORD('123456');
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> exit;
6.设置开机启动MariaDB
chkconfig --add mysqld
chkconfig mysqld on
附
报错:/usr/local/mysql/bin/mysql: error while loading shared libraries: libiconv.so.2: cannot open shared object file: No such file or directory
解决办法:
ln -sf /usr/local/lib/libiconv.so.2 /usr/lib/libiconv.so.2
ldconfig