mysql安装(5.7)(CentOS7.0)

1、先安装依赖库(yum安装)

yum install -y cmake make gcc gcc- c++ bison ncurses ncurses-devel

2、下载Boost1.59.0源代码,并解压到/home/develop/目录下,修改名称为boost

tar –zxvf boost_1_59_0.tar.gz
mv boost_1_59_0 boost

3、添加mysql用户,用户组

添加mysql用户组

group add mysql

添加mysql用户

useradd -r -g mysql -s /bin/false mysql

4、下载mysql5.7源码,并解压到/home/develop下

tar –zxvf mysql-5.7.18_.tar.gz

5、新建mysql安装目录和mysql存放数据目录

mkdir mkdir mysql
cd mysql
mkdir data
chown -R mysql:mysql /home/develop/mysql

6、预编译在解压MySQL目录下执行

cmake . -DCMAKE_INSTALL_PREFIX=/home/develop/mysql
-DMYSQL_DATADIR=/home/develop/mysql/data
-DWITH_BOOST=/home/develop/boost
-DSYSCONFDIR=/etc
-DDEFAULT_CHARSET=utf8
-DDEFAULT_COLLATION=utf8_unicode_ci
-DENABLED_LOCAL_INFILE=1
-DEXTRA_CHARSETS=all

7、编译并安装(红色部分用``括起来)

make -j grep processor /proc/cpuinfo | wc -l && make install

8、新建mysql配置文件/etc/my.cnf,内容如下

[mysql]
 # 设置mysql客户端默认字符集
default-character-set=utf8 
socket=/home/develop/mysql/mysql.sock
[mysqld]
user=mysql
port=3306
basedir=/home/develop/mysql
datadir=/home/develop/mysql/data
tmpdir=/home/develop/mysql/temp
socket=/home/develop/mysql/mysql.sock
explicit_defaults_for_timestamp=true
open_files_limit=10240
back_log=600
max_connections=500
max_connect_errors=6000
wait_timeout=605800
max_allowed_packet=32M
sort_buffer_size=4M
join_buffer_size=4M
thread_cache_size=300
query_cache_type=1
query_cache_size=256M
query_cache_limit=2M
query_cache_min_res_unit=16k
tmp_table_size=256M
max_heap_table_size=256M
key_buffer_size=256M
read_buffer_size=1M
read_rnd_buffer_size=16M
bulk_insert_buffer_size=64M
lower_case_table_names=1
default-storage-engine=INNODB
innodb_buffer_pool_size=2G
innodb_log_buffer_size=32M
innodb_log_file_size=128M
innodb_flush_method=O_DIRECT
long_query_time=2

[mysqldump]
quick
max_allowed_packet=32M
 # Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
character-set-server=utf8
collation-server=utf_unicode_ci
skip-external-locking
skip-name-resolve

[mysqld_safe]

9、初始化系统数据库并加密

cd mysql
mkdir temp
chown –R mysql:mysql /home/develop/mysql
./bin/mysqld --initialize-insecure --user=mysql --basedir=/home/develop/mysql --datadir=/home/develop/mysql/data
./bin/mysql_ssl_rsa_setup

10、配置mysql环境变量

在/etc/profile后面追加 export PATH=/home/develop/mysql/bin:$PATH
立即生效

source /etc/profile

11、配置mysql服务,开机自启

cd /home/develop/mysql
cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld
chmod +x /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
chkconfig --list mysqld
chkconfig mysqld on

12、启动mysql服务

启动mysql

systemctl start mysql

停止mysql

systemctl stop mysql

重启mysql

systemctl restart mysql

查看mysql状态

systemctl status mysql

13、设置防火墙

开启mysql 3306端口号

firewall-cmd --zone=public --add-port=3306/tcp --permanent

重启防火墙

firewall-cmd --reload

14、设置数据库密码

连接mysql,给当前root用户设置密码(mysql –u root –p123456)

set password=password('123456');

新建mysql用户并授权开启远程登录(将host设为%即可)

grant all privileges on . to mysql@'%' identified by '123456' with grant option;

生效

flush privileges;

你可能感兴趣的:(mysql安装(5.7)(CentOS7.0))