Mysql5.6源码安装及其简单优化

1,下载mysql-5.6.29

http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.29.tar.gz

2,必要软件包

yum -y install gcc-c++ ncurses-devel cmake make perl gcc bison autoconf automake zlib* fiex* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel*

3,添加用户

groupadd mysql

useradd -r -g mysql mysql

4,编译安装参数

cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \

-DMYSQL_DATADIR=/web/data \

-DSYSCONFDIR=/etc \

-DWITH_MYISAM_STORAGE_ENGINE=1 \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_MEMORY_STORAGE_ENGINE=1 \

-DWITH_READLINE=1 \

-DMYSQL_UNIX_ADDR=/var/lib/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

#编译的参数可以参考http://dev.mysql.com/doc/refman/5.6/en/source-configuration-options.html

5,改变目录所有者

chown -R mysql.mysql /usr/local/mysql

6,初始化数据库

cd /usr/local/mysql/scripts

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

mysql5.6初始化数据库

./mysqld initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data

mysql5.7初始化数据

7,注册为服务

cd /usr/local/mysql/support-files

#注册服务

cp mysql.server /etc/rc.d/init.d/mysqld

#使用默认配置文件

cp my-default.cnf /etc/my.cnf

#让chkconfig管理mysql服务

chkconfig --add mysqld

#开机启动

chkconfig mysqld on

8,启动MySQL服务

# service mysqld start

9,改变编码,防止乱码

查看字符编码:SHOW VARIABLES LIKE 'character%'

修改mysql的my.cnf文件:

[client]

default-character-set=utf8

[mysqld]

port = 3306

character-set-server=utf8

datadir=/web/data
innodb_file_per_table = ON
skip_name_resolve = ON

[mysql]

default-character-set=utf8

10,把mysql的bin添加全局变量:

[root@local mysql]# vi  /etc/profile.d/mysql.sh

export PATH=/usr/local/mysql/bin:$PATH

[root@local mysql]# .  /etc/profile.d/mysql.sh 让其生效

11,用户和远程访问权限配置:

[root@tomcat2 ~]# mysql -uroot

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 2

Server version: 5.6.29 Source distribution

mysql> SET PASSWORD = PASSWORD('mysql888');

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'mysql888' WITH GRANT OPTION;

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY 'mysql888' WITH GRANT OPTION;

mysql> flush privileges;

My.cnf配置文件优化

[mysqld]

port            = 3306

socket          = /tmp/mysql.sock

skip-external-locking

key_buffer_size = 384M

max_allowed_packet = 1M

table_open_cache = 512

sort_buffer_size = 2M

read_buffer_size = 2M

read_rnd_buffer_size = 8M

myisam_sort_buffer_size = 64M

thread_cache_size = 8

query_cache_size = 32M

# Try number of CPU's*2 for thread_concurrency

thread_concurrency = 1

datadir=/web/data

innodb_file_per_table = ON

innodb_buffer_pool_size=64M  #inno引擎的缓存池大小

skip_name_resolve = ON

max_connections = 50 #数据库的最大连接

mysql


发表评论

登录 后发表评论.