[ 卸载 MySQL ]
① 检查是否安装有MySQL Server
# rpm -qa | grep mysql
② 删除 MySQL
# rpm -qa | grep mysql
mysql-libs-5.1.73-7.el6.x86_64 // 查询到的结果
# rpm -e mysql-libs-5.1.73-7.el6.x86_64 // 普通删除模式
# rpm -e --nodeps mysql-libs-5.1.73-7.el6.x86_64 // 强力删除模式
[ 安装 MySQL 依赖 ]
① 安装GCC编译器
❶ 进入 /usr/local/ 目录
# cd /usr/local/
❷ 在线安装
# yum -y install gcc gcc-c++ make autoconf libtool-ltdl-devel gd-devel freetype-devel libxml2-devel libjpeg-devel libpng-devel openssl-devel curl-devel bison patch unzip libmcrypt-devel libmhash-devel ncurses-devel sudo bzip2 flex libaio-devel
② 安装cmake 编译器
❶ 开始下载 cmake 安装包
# wget -P /usr/local/ http://www.cmake.org/files/v3.1/cmake-3.1.1.tar.gz
❷ 进入 /usr/local/ 目录
# cd /usr/local/
❸ 解压安装包
# tar zxvf cmake-3.1.1.tar.gz
❹ 删除安装包
# rm -rf cmake-3.1.1.tar.gz
❺ 进入安装包目录
# cd cmake-3.1.1
❻ 编译安装
# ./bootstrap
# make && make install
[ 安装 MySQL ]
① MySQL 安装包下载
# wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.43.tar.gz
② 解压安装包
# tar zxvf mysql-5.6.43.tar.gz
③ 删除安装包
# rm -rf mysql-5.6.43.tar.gz
④ 创建mysql目录
# mkdir /usr/local/mysql
⑤ 创建MySQL数据目录
# mkdir /usr/local/mysql/data
⑥ 移动安装包到mysql目录
# mv mysql-5.6.43 /usr/local/mysql/
⑦ 进入安装包目录
# cd /usr/local/mysql/mysql-5.6.43/
⑧ 编译安装
# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql/ -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DWITH_INNODB_MEMCACHED=1 -DWITH_DEBUG=OFF -DWITH_ZLIB=bundled -DENABLED_LOCAL_INFILE=1 -DENABLED_PROFILING=ON -DMYSQL_MAINTAINER_MODE=OFF -DMYSQL_DATADIR=/usr/local/mysql/data -DMYSQL_TCP_PORT=3306
# make && make install
⑨ 查看mysql版本:
# /usr/local/mysql/bin/mysql --version
[ MySQL 配置 ]
① 创建mysql运行使用的用户mysql:
# /usr/sbin/groupadd mysql
# /usr/sbin/useradd -g mysql mysql
② 创建binlog和库的存储路径并赋予mysql用户权限
# mkdir -p /usr/local/mysql/binlog /www/data_mysql
# chown mysql.mysql /usr/local/mysql/binlog/ /www/data_mysql/
③ 编辑 my.cnf 配置文件(配置中文详解)
❶ 开始编辑
# vim /ect/my.cnf
❷ 将/etc/my.cnf替换为下面内容
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
replicate-ignore-db = mysql
replicate-ignore-db = test
replicate-ignore-db = information_schema
user = mysql
port = 3306
socket = /tmp/mysql.sock
basedir = /usr/local/mysql
datadir = /www/data_mysql
log-error = /usr/local/mysql/mysql_error.log
pid-file = /usr/local/mysql/mysql.pid
open_files_limit = 65535
back_log = 600
max_connections = 5000
max_connect_errors = 1000
table_open_cache = 1024
external-locking = FALSE
max_allowed_packet = 32M
sort_buffer_size = 1M
join_buffer_size = 1M
thread_cache_size = 600
#thread_concurrency = 8
query_cache_size = 128M
query_cache_limit = 2M
query_cache_min_res_unit = 2k
default-storage-engine = MyISAM
default-tmp-storage-engine=MYISAM
thread_stack = 192K
transaction_isolation = READ-COMMITTED
tmp_table_size = 128M
max_heap_table_size = 128M
log-slave-updates
log-bin = /usr/local/mysql/binlog/binlog
binlog-do-db=oa_fb
binlog-ignore-db=mysql
binlog_cache_size = 4M
binlog_format = MIXED
max_binlog_cache_size = 8M
max_binlog_size = 1G
relay-log-index = /usr/local/mysql/relaylog/relaylog
relay-log-info-file = /usr/local/mysql/relaylog/relaylog
relay-log = /usr/local/mysql/relaylog/relaylog
expire_logs_days = 10
key_buffer_size = 256M
read_buffer_size = 1M
read_rnd_buffer_size = 16M
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
myisam_recover
interactive_timeout = 120
wait_timeout = 120
skip-name-resolve
#master-connect-retry = 10
slave-skip-errors = 1032,1062,126,1114,1146,1048,1396
#master-host = 192.168.1.2
#master-user = username
#master-password = password
#master-port = 3306
server-id = 1
loose-innodb-trx=0
loose-innodb-locks=0
loose-innodb-lock-waits=0
loose-innodb-cmp=0
loose-innodb-cmp-per-index=0
loose-innodb-cmp-per-index-reset=0
loose-innodb-cmp-reset=0
loose-innodb-cmpmem=0
loose-innodb-cmpmem-reset=0
loose-innodb-buffer-page=0
loose-innodb-buffer-page-lru=0
loose-innodb-buffer-pool-stats=0
loose-innodb-metrics=0
loose-innodb-ft-default-stopword=0
loose-innodb-ft-inserted=0
loose-innodb-ft-deleted=0
loose-innodb-ft-being-deleted=0
loose-innodb-ft-config=0
loose-innodb-ft-index-cache=0
loose-innodb-ft-index-table=0
loose-innodb-sys-tables=0
loose-innodb-sys-tablestats=0
loose-innodb-sys-indexes=0
loose-innodb-sys-columns=0
loose-innodb-sys-fields=0
loose-innodb-sys-foreign=0
loose-innodb-sys-foreign-cols=0
slow_query_log_file=/usr/local/mysql/mysql_slow.log
long_query_time = 1
[mysqldump]
quick
max_allowed_packet = 32M
❸ 保存退出
# esc:wq
④ 进入安装目录
# cd /usr/local/mysql
⑤ 初始化数据库
# /usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --user=mysql
⑥ 创建开机启动脚本
# cd /usr/local/mysql/
# cp support-files/mysql.server /etc/rc.d/init.d/mysql
# chkconfig --add mysql
# chkconfig --level 35 mysql on
⑦ 设置权限
# cd ../
# chown -R mysql:mysql mysql
⑧ MySQL 命令
# 启动:service mysql start
# 停止:service mysql stop
# 重启:service mysql restart
# 重载配置:service mysql reload
⑨ mysql_error.log 报错
❶ 如果授权后,启动报错下面错误
❷ 创建一个mysql_error.log
⑩ 登录 MySQL
# /usr/local/mysql/bin/mysql -u root -p
⑪ 设置MySQL用户密码
# set password = password("root");
⑫ 创建新用户并授权:
# grant all privileges on *.* to 用户名@'%' identified by '密码' with grant option;
⑬ 设置远程访问用户
# grant all privileges on *.* to 'root' @'%' identified by '密码';
# flush privileges;
⑭ 开启3306端口号访问(ROOT用户设置)
# /sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
⑮ 数据库可视化工具测试连接