centos6 源码安装mysql5.6

一.系统初始化

setenforce 0
sed -i "s/^SELINUX=.*/SELINUX=disabled/" /etc/sysconfig/selinux
service iptables stop
chkconfig iptables off

二. 安装mysql

yum install -y autoconf automake cmake gcc-c++ libgcrypt libtool libxml2 ncurses-devel zlib perl-Data-Dumperpython-devel openssl openssl-devel bison-devel   #安装工具包和依赖包
wget http://ftp.ntu.edu.tw/MySQL/Downloads/MySQL-5.6/mysql-5.6.36.tar.gz  #下载mysql5.6源码包
useradd  -s /sbin/nologin -M mysql    #创建mysql系统用户
mkdir /apps/data -p #创建存放数据库的文件夹
mkdir /apps/log
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/apps/data \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci 

make && make install

三.配置mysql

chown -R mysql:mysql /usr/local/mysql 
chown -R mysql:mysql /apps/data
chown -R mysql:mysql /apps/log
cd /usr/local/mysql/
cp support-files/mysql.server  /etc/init.d/mysqld

修改/etc/my.cnf

[mysqld]
user=mysql
port = 3306
basedir = /usr/local/mysql
datadir =/apps/data
log_bin=/apps/data/log/mysql-bin
log-error=/apps/data/log/error.log
pid-file=/usr/local/mysql/mysqld.pid
socket=/usr/local/mysql/mysql.sock 
lower_case_table_names=1
character-set-client-handshake = FALSE
character-set-server = utf8
collation-server = utf8_unicode_ci
init_connect = 'SET NAMES utf8'
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[mysql]
default-character-set=utf8
[client]
default-character-set=utf8

具体生产配置参考:my.cnf

chkconfig mysqld on
#执行初始化配置脚本
/usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/apps/data --user=mysql
#service mysqld start

mysql命令加入环境变量

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

mysql 设置密码

mysqladmin -uroot password '123456'

mysql安全配置向导
如下:

# mysql_secure_installation
Enter current password for root (enter for none):
    新安装的mysql无root密码,按Enter即可
Set root password? [Y/n] Y
    设置root密码
Remove anonymous users? [Y/n] Y
    删除匿名用户
Disallow root login remotely? [Y/n] Y
    取消root远程登录
Remove test database and access to it? [Y/n] Y
    删除test数据库
Reload privilege tables now? [Y/n] Y
    刷新权限

或:
进入mysql客户端

mysql> use mysql;
#删除匿名用户
mysql> delete from user where user="";
#删除空密码的root
mysql> delete from user where user='root' and password="";
#取消root远程登录
mysql> delete from user where user='root' and host="%";
#删除test数据库
mysql> drop database test;
#刷新权限
mysql> FLUSH PRIVILEGES;

重设密码 mysqld_safe --skip-grant-tables & 进入数据库设置密码。

你可能感兴趣的:(centos6 源码安装mysql5.6)