CentOS6下源码安装mysql-5.6.25

1.1.系统环境检查 

1)检查系统版本

mkdir -p /server/tools/
cd /server/tools/
cat /etc/redhat-release

2)配置域名解析

vim /etc/hosts
-------------------------------
127.0.0.1    mysql-server
-------------------------------

3)安装cmake编译工具和依赖包

yum install cmake ncurses-devel -y

1.2.源码安装mysql

1)创建mysql运行用户和组

groupadd mysql
useradd mysql -s /sbin/nologin -M -g mysql

2)配置编译安装

# 源码配置,下载或者上传该版本的mysql安装包

#wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.25.tar.gz
tar -zxf mysql-5.6.25.tar.gz
cd /server/tools/mysql-5.6.25/
---------------------------------------
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=all \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DWITH_FAST_MUTEXES=1 \
-DWITH_ZLIB=bundled \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_READLINE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DWITH_DEBUG=0
----------------------------------------

# 编译安装(时间比较长)

make && make install

3)修改mysql配置文件

# 创建mysql相关目录并修改权限属主

mkdir -p /usr/local/mysql/{data,logs}
chown -R mysql.mysql /usr/local/mysql
ll /usr/local/
ll /usr/local/mysql/

# 调整/tmp目录的权限,防止初始化错误

chmod -R 1777 /tmp
ll /tmp -d

# 修改优化my.cnf配置文件

mv /etc/my.cnf /etc/my.cnf.old
cp support-files/my-default.cnf /etc/my.cnf
vim /etc/my.cnf
-------------------------
[mysqld]
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
pid-file = /usr/local/mysql/logs/mysqld.pid
log-error = /usr/local/mysql/logs/error.log
socket = /tmp/mysql.sock
bind-address = 0.0.0.0
max_connections = 500
thread_cache_size = 50
lower_case_table_names = 1
explicit_defaults_for_timestamp = true

log_bin = /usr/local/mysql/data/mysql-bin
expire_logs_days = 10
binlog_format = row
binlog_row_image = full
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 

[client]
port = 3306
socket = /tmp/mysql.sock
--------------------------

其他可选配置:

default-storage-engine = innodb
innodb_file_per_table
collation-server = utf8_general_ci
init-connect = 'SET NAMES utf8'
character-set-server = utf8    # 配置数据库默认字符集
max_binlog_size = 1G
binlog_format = row        # 配置binlog格式,用于数据恢复,可能会降低性能
binlog_row_image = full        # 

4)初始化数据库

# 配置环境变量

echo "export PATH=/usr/local/mysql/bin:$PATH" >> /etc/profile
tail -1 /etc/profile
source /etc/profile
echo $PATH

# 创建数据表,看到两个OK信息表示mysql初始化成功

cd /usr/local/mysql/scripts/
./mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/ --user=mysql 

5)启动mysql数据库

# 配置启动脚本文件

cd /usr/local/mysql
cp support-files/mysql.server  /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld 
/etc/init.d/mysqld start   
netstat -anptl |grep 3306

# 配置开机启动mysql

chkconfig --add mysqld 
chkconfig mysqld on
chkconfig --list mysqld

1.3.清理默认安装的测试库和用户

# 新安装的mysql数据库默认会有一些多余的用户和数据库,如果在初始化的时候没有选择清理,可以在数据库初始化完成后手动清理下,增强mysql的安全性

# 也可以根据数据库初始化后的提示使用脚本初始化数据库用户密码和删除测试库

1)查询mysql初始用户

mysql
select user,host from mysql.user;

2)删除空用户名和空密码用户的登陆方式

delete from mysql.user where user=" ";
delete from mysql.user where password='';

3)删除主机名登陆的用户方法

# delete from mysql.user where host="主机名";
delete from mysql.user where host='::1';

4)删除测试test库

show databases ;
drop database test;

# 最终结果如下

-------------------------------
mysql> show databases ;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)

mysql> select user,host from mysql.user;
+------+-----------+
| user | host      |
+------+-----------+
| root | 127.0.0.1 |
| root | localhost |
+------+-----------+
2 rows in set (0.00 sec)
--------------------------------

==== 完毕,呵呵呵呵 ====

posted @ 2018-01-25 11:40  天生帅才  阅读(402)  评论(0编辑  收藏  举报
// 百度统计