下载地址:https://downloads.mariadb.org/mariadb/10.2.10/
##
二进制压缩包安装
安装包
mariadb-10.2.10-linux-x86_64.tar.gz
软件目录 /opt/mysql
数据目录 /data/mysql/data
### 环境配置
yum -y install readline-devel zlib-devel openssl-devel libaio-devel
### 安装
groupadd mysql
useradd -g mysql mysql
mkdir -p /data/mysql/data
chown -R mysql
/data/mysql
cd /opt
tar -xf mariadb-10.2.10-linux-x86_64.tar.gz
mv mariadb-10.2.10-linux-x86_64 mysql
cd mysql
./scripts/mysql_install_db --user=mysql --datadir=
/data/mysql/data
### 添加环境变量
vim /etc/profile 添加
export PATH=$PATH:/opt/mysql/bin
source
/etc/profile
### 配置my.cnf文件
vim /opt/mysql/my.cnf
[client] port = 3306 socket = /data/mysql/data/mysql.sock [mysql] prompt = "\u@rac2 \R:\m:\s [\d]> " [mysqld] user = mysql port = 3306 basedir = /opt/mysql datadir = /data/mysql/data socket = /data/mysql/data/mysql.sock slow_query_log = 1 slow_query_log_file = /data/mysql/data/slow.log log-error = /data/mysql/data/error.log long_query_time = 0.5 log_queries_not_using_indexes =1 log_throttle_queries_not_using_indexes = 60 log_slow_admin_statements = 1 log_slow_slave_statements = 1 server-id = 3306 log-bin = /data/mysql/data/mybinlog sync_binlog = 1 expire_logs_days = 30 transaction_isolation = REPEATABLE-READ innodb_buffer_pool_size =50M innodb_buffer_pool_instances = 1 innodb_buffer_pool_load_at_startup = 1 innodb_buffer_pool_dump_at_shutdown = 1 #innodb_data_file_path = ibdata1:50M:autoextend innodb_flush_log_at_trx_commit = 1 innodb_log_buffer_size = 32M innodb_log_file_size = 50M innodb_log_files_in_group = 2 innodb_max_undo_log_size = 200M |
### 启动mysql
mysqld_safe --defaults-file=/opt/mysql/my.cnf --user=mysql &
### 配置root账户
mysql --socket=/data/mysql/data/mysql.sock
MariaDB [(none)]> grant all on *.* to root@'localhost' identified by 'rootroot';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> grant all on *.* to root@'%' identified by 'rootroot';
Query OK, 0 rows affected (0.00 sec)
### 删除匿名用户
MariaDB [(none)]> select user,host from mysql.user;
MariaDB [(none)]> select user,host from mysql.user where user='' or host='';
MariaDB [(none)]> delete from mysql.user where user='' or host='';
### 验证账号是否生效
[root@mysql-master bin]# mysql -uroot -p
--socket=/data/opt/mysql/mysql.sock
### 配置别名(可选)
vim /root/.bashrc
alias mysql3306='/opt/mysql/bin/mysql
-uroot -prootroot
--socket=/data/mysql/data/mysql.sock'
alias stop_mysql_3306='mysqladmin shutdown -uroot -p"rootroot"
--socket=/data/mysql/data/mysql.sock'
alias start_mysql_3306='
mysqld_safe --defaults-file=/opt/mysql/my.cnf --user=mysql &'
|
## yum安装
cd /etc/yum.repos.d
mkdir bak
mv ./*.repo bk
配置yum源
vim mysql.repo
[mariadb] name = MariaDB baseurl = http://yum.mariadb.org/10.2/centos6-amd64 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=0 enabled=1 |
yum install boost
yum install MariaDB-server MariaDB-client
sudo systemctl start mariadb
sudo /etc/init.d/mysql start
参考地址:https://mariadb.com/kb/en/library/yum/
参考地址:
https://downloads.mariadb.org/mariadb/repositories/#mirror=neusoft&distro=CentOS&distro_release=centos6-amd64--centos6&version=10.2
## 源码安装
安装包mariadb-10.2.10.tar
软件目录 /opt/mysql
数据目录 /data/mysql/data
yum install -y ncurses-devel openssl-devel openssl gcc-c++ cmake
groupadd mysql
useradd -g mysql mysql
gunzip mariadb-10.2.10.tar.gz
tar -xf mariadb-10.2.10.tar
cd mariadb-10.2.10
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mydata -DSYSCONFDIR=/etc -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DWITH_SSL=system -DWITH_ZLIB=system -DWITH_LIBWRAP=0 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
make
make install
cd /usr/local/mysql
scripts/mysql_install_db --user=mysql --datadir=/data/mariadb/data/
vim /usr/local/mysql/my.cnf 修改配置文件
[mysqld] datadir=/data/mariadb/data socket=/data/mariadb/data/mysql.sock user=mysql # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 [mysqld_safe] log-error=/var/log/mysqld.log pid-file=/data/mariadb/data/mysqld.pid |
export PATH=$PATH:/usr/local/mysql
chown -R mysql
/data/mariadb
启动mysql
mysqld_safe --defaults-file=/usr/local/mysql/my.cnf &
登陆mysql
mysql -uroot -p --socket=/data/mariadb/data/mysql.sock
参考文档:https://www.cnblogs.com/daixiang/p/5431639.html
## mysql升级方法
1.在目标服务器上安装新版本的 MySQL
2.在新版本 MySQL 上创建和老版本同名的数据库
mysqladmin -h hostname -P port -u user -p passwd create db_name
3.将老版本 MySQL 上的数据库通过管道导入到新版本数据库中。命令如下:
mysqldump --opt db_name | mysql -h hostname -P port -u user -p passwd
db_name
说明:
--opt 选项表明采用优化(Optimize)方式进行导出
如果网络较慢,可以在导出选项中加上--compress 来减少网络传输
对于不支持管道操作符(|)的操作系统,可以先用 mysqldump 工具将旧版本的数据导出为 文本文件,然后再往新版本 MySQL 中导入此文件
shell> mysqldump --opt db_name > filename(旧版本 MySQL 上执行)
shell> mysql –u user –p passwd db_name < filename(新版本 MySQL 上执行)
4.将旧版本 MySQL 中的 mysql 数据库目录全部 cp 过来覆盖新版本 MySQL 中的 mysql 数据库
#配置GTID
mysqld_safe --gtid_mode=ON --log-bin --log-slave-updates --enforce-gtid-consistency &
./bin/mysqld_safe --defaults-file=/data/opt/mysql/my.cnf --user=mysql --gtid_mode=ON --log-bin --log-slave-updates &
主从配置gtid参考
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/31385999/viewspace-2150209/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/31385999/viewspace-2150209/