安装工具
root@Toka:~# apt-get install libncurses5-dev
root@Toka:~# Redhat和其他Linux版本对应的是ncurses-devel,这里安装的母鸡是Debian
再安装cmake
root@Toka:~# wget https://cmake.org/files/v3.7/cmake-3.7.2.tar.gz
root@Toka:~# tar -zxvf cmake-3.7.0.tar.gz
root@Toka:~# cd cmake-3.7.0
root@Toka:~# ./bootstrap
root@Toka:~# make
root@Toka:~# make install
下载MariaDB:mariadb-10.1.19.tar.gz 或 mariadb-10.1.20-linux-glibc_214-x86_64.tar.gz这里以mariadb-10.1.19.tar.gz为示例安装
root@Toka:~# wget https://mirrors.tuna.tsinghua.edu.cn/mariadb//mariadb-10.1.19/source/mariadb-10.1.19.tar.gz
root@Toka:~# tar -zxvf mariadb-10.1.19.tar.gz
root@Toka:~# cd mariadb-10.1.19
root@Toka:~# cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DSYSCONFDIR=/etc/mysql \
-DMYSQL_USER=mysql \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/var/run/mysqld/mysqld.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DENABLE_DOWNLOADS=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_DEBUG=0 \
-DMYSQL_MAINTAINER_MODE=0 \
-DWITH_SSL:STRING=bundled \
-DWITH_ZLIB:STRING=bundled \
-DWITHOUT_MROONGA_STORAGE_ENGINE=1
出错:
/usr/bin/ld: cannot find -lz
collect2: error: ld returned 1 exit status
storage/tokudb/PerconaFT/ft/CMakeFiles/ft.dir/build.make:1382: recipe for target 'storage/tokudb/PerconaFT/ft/libft.so' failed
make[2]: *** [storage/tokudb/PerconaFT/ft/libft.so] Error 1
-DWITH_ZLIB=/usr/local/src/zlib-1.2.8
root@Toka:~# 按上面错误提示可知缺少zlib1g,安zlib1g-dev解决
root@Toka:~# apt-get install zlib1g-dev
root@Toka:~# 重新再次安装
root@Toka:~# cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DSYSCONFDIR=/etc/mysql \
-DMYSQL_USER=mysql \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/var/run/mysqld/mysqld.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DENABLE_DOWNLOADS=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_DEBUG=0 \
-DMYSQL_MAINTAINER_MODE=0 \
-DWITH_SSL:STRING=bundled \
-DWITH_ZLIB:STRING=bundled \
-DWITHOUT_MROONGA_STORAGE_ENGINE=1
警告:Warning: Bison executable not found in PATH
root@Toka:~# apt-get install bison
root@Toka:~# 解决后,重新再次安装
root@Toka:~# cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DSYSCONFDIR=/etc/mysql \
-DMYSQL_USER=mysql \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/var/run/mysqld/mysqld.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DENABLE_DOWNLOADS=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_DEBUG=0 \
-DMYSQL_MAINTAINER_MODE=0 \
-DWITH_SSL:STRING=bundled \
-DWITH_ZLIB:STRING=bundled \
-DWITHOUT_MROONGA_STORAGE_ENGINE=1
这下完好,不警告:
-- Configuring done
-- Generating done
-- Build files have been written to: /usr/local/src/mariadb-10.1.19
可以放心进行下一步安装了!!
root@Toka:~# make
[100%] Built target my_safe_process
root@Toka:~# 没报错,继续
root@Toka:~# make install
经过以上安装大功告成!!!
不过还要添加mysql环境变量,不然每次打mysql命令时都要打绝对路径才能生效。
root@Toka:~# echo -e '\n export PATH=$PATH:/usr/local/mysql/bin \n' >> ~/.bashrc && source ~/.bashrc
接下来创建mysql用户和组
root@Toka:~# groupadd mysql
root@Toka:~# useradd -r -g mysql -s /bin/false mysql
接下来简单配置一下,才可以用
root@Toka:~# chown -R mysql:mysql /usr/local/mysql/data
root@Toka:~# mkdir /var/run/mysqld
root@Toka:~# chown -R mysql:mysql /var/run/mysqld/
root@Toka:~# cd /usr/local/mysql
root@Toka:~# mkdir /etc/mysql
root@Toka:~# cp support-files/my-small.cnf /etc/mysql/my.cnf
root@Toka:~# 修改配置文件:
root@Toka:~# vim /etc/mysql/my.cnf
# 在[client]下添加以下行
default-character-set = utf8
# 在[mysqld]下添加以下行
character-set-server = utf8
root@Toka:~# 初始化数据库
root@Toka:~# scripts/mysql_install_db --user=mysql
root@Toka:~# 先启动mysql
root@Toka:~# /usr/local/mysql/support-files/mysql.server start
root@Toka:~# 再执行修改密码:
root@Toka:~# /usr/local/mysql/bin/mysql_secure_installation
提示:Enter current password for root (enter for none):
直接回车,因为我们刚安装还没有密码
提示:Set root password? [Y/n]
输入:y
提示:New password:
输入新密码
提示:Re-enter new password:
重新输入刚才的密码
提示:Remove anonymous users? [Y/n]
输入:y
提示:Disallow root login remotely? [Y/n]
输入:n
提示:Remove test database and access to it? [Y/n]
输入:y
提示:Reload privilege tables now? [Y/n]
输入:y
All done! If you've completed all of the above steps, your MariaDB installation should now be secure.
Thanks for using MariaDB!
root@Toka:~# 再执行如下修改root用户可远程登录
root@Toka:~# mysql -h localhost -u root -p
mysql -h localhost -u root -p
MariaDB [(none)]> use mysql
MariaDB [mysql]> update user set host='%' where user='root' and host='localhost';
MariaDB [mysql]> select host from user where user='root';
+-----------+
| host |
+-----------+
| % |
| 127.0.0.1 |
| ::1 |
| debian |
+-----------+
4 rows in set (0.00 sec)
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> exit;
root@Toka:~# 至此数据库安装完成!!
安装MariaDB到此全部完成
日常重启控制命令:
启动:/usr/local/mysql/support-files/mysql.server start
停止:/usr/local/mysql/support-files/mysql.server stop
重启:/usr/local/mysql/support-files/mysql.server restart
MariaDB官网:https://downloads.mariadb.org/
参考:
https://mariadb.com/kb/zh-cn/installing-mariadb-binary-tarballs/
http://opso.coding.me/2016/03/29/mariadb-install/
http://cloudline.iteye.com/blog/867772
=====================================================================================
MySql主从配置:
=====================================================================================
1.1、版本一致
##1.2、初始化表,并在后台启动mysql
##1.3、修改root的密码
-------------------------------------------------------------------------------------
修改主服务器master:
vim /usr/local/mysql/my.cnf
#服务器唯一ID,默认是1,一般取IP最后一段
server-id=154
#启用二进进制日志
log-bin=mysql-bin
# binlog-do-db = testdb #只记录testdb库变化,多个库用‘,’分隔
# binlog-ignore-db=mysql #忽略mysql库变化,多个库用‘,’分隔
# expire_logs_days =7 #binlog日志只保留7天内的数据
-------------------------------------------------------------------------------------
修改从服务器slave:
vim /usr/local/mysql/my.cnf
#服务器唯一ID,默认是1,一般取IP最后一段
server-id=135
#启用二进进制日志
log-bin=mysql-bin
#log-slave-updates #级联复制(A->B->C)
# expire_logs_days =7 #binlog日志只保留7天内的数据
# replicate-ignore-db=mysql #不同步mysql库,多个库用‘,’分隔
# replicate-do-db = testdb #只同步testdb库,多个库用‘,’分隔
# replicate-do-table = test_tb #只同步test_tb表,多个表用‘,’分隔
# replicate-ignore-table = test_tb #不同步test_tb表,多个表用‘,’分隔
# replicate-wild-do-table = test_tb #同表,可以加通配符(replicate-wild-do-table=db_name.%) 只复制哪个库的哪个表
# replicate-wild-ignore-table = test #不同步的表,通配符来规则范围(replicate-wild-ignore-table=mysql.%)忽略哪个库的哪个表
重启两台服务器的mysql
/usr/local/mysql/support-files/mysql.server restart
--------------------------------------------------------------------------------------
在主服务器上建立帐户并授权slave:
#/usr/local/mysql/bin/mysql -uroot -p
mysql> GRANT REPLICATION SLAVE ON *.* to 'mysync'@'%' identified by 'syncpasswd';
##一般不用root帐号,“%”表示所有客户端都可能连,只要帐号,密码正确,此处可用具体客户端IP代替,如192.168.145.226,加强安全。
mysql> FLUSH PRIVILEGES;
登录主服务器的mysql,查询master的状态
mysql> show master status; ###记住记住下面这两个值,从服务器中要用到
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000002 | 607 | | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
注:执行完此步骤后不要再操作主服务器MYSQL,防止主服务器状态值变化
-----------------------------------------------------------------------------------------------
配置从服务器Slave:
mysql> change master to master_host='218.16.120.154',
master_user='mysync',
master_password='syncpasswdcmb7d',
master_log_file='mysql-bin.000002',
master_log_pos=607;
mysql> start slave; ##这里是开户从服务(停止为:stop slave)
mysql> show slave status\G;
Master_Log_File: mysql-bin.000002
Read_Master_Log_Pos: 607
Relay_Log_File: debian-relay-bin.000002
Relay_Log_Pos: 770
Relay_Master_Log_File: mysql-bin.000002
Slave_IO_Running: Yes ###这个必须为YES
Slave_SQL_Running: Yes ###这个必须为YES
-----------------------------------------------------------------------------------------------
如果从服务器配置出错,可以先重围( reset slave;)再配置就可以了!
到此就主从MySql就配置完成了,可以测试了。
注:MySql每次重启都要重新配置主从同步哦!!