首页 > 代码库 > mysql二进制安装

mysql二进制安装

上传文件并解压

[root@MySQL ~]# cd /usr/local/
[root@MySQL local]# ls mysql*
mysql-5.7.9-linux-glibc2.5-x86_64.tar.gz
[root@MySQL local]# tar zxvf mysql-5.7.9-linux-glibc2.5-x86_64.tar.gz


解压完毕之后创建软连接

[root@MySQL local]# ln -s mysql-5.7.9-linux-glibc2.5-x86_64 mysql

[root@MySQL local]# cd mysql
[root@MySQL mysql]# ll
total 160
drwxr-xr-x 2 7161 wheel 4096 Oct 12 2015 bin
-rw-r--r--    1 7161 wheel 17987 Oct 12 2015 COPYING
drwxr-xr-x  2 7161 wheel 4096 Oct 12 2015 docs
drwxr-xr-x  3 7161 wheel 4096 Oct 12 2015 include
-rw-r--r--     1 7161 wheel 108028 Oct 12 2015 INSTALL-BINARY
drwxr-xr-x   5 7161 wheel 4096 Oct 12 2015 lib
drwxr-xr-x   4 7161 wheel 4096 Oct 12 2015 man
-rw-r--r--     1 7161 wheel 2478 Oct 12 2015 README
drwxr-xr-x 28 7161 wheel 4096 Oct 12 2015 share
drwxr-xr-x   2 7161 wheel 4096 Oct 12 2015 support-files


创建用户及组

[root@MySQL mysql]# groupadd mysql
[root@MySQL mysql]# useradd -r -g mysql mysql

 

为mysql路径下面的文件进行用户和组的修改

[root@MySQL mysql]# chown -R mysql .
[root@MySQL mysql]# chgrp -R mysql .

 

创建数据文件和日志文件路径

[root@MySQL local]# mkdir /mydata /mydata/data /mydata/log
[root@MySQL mysql]# chown -R mysql:mysql /mydata

 

创建my.cnf文件

[root@MySQL mysql]# vi /etc/my.cnf

[client]
port = 3306
socket = /var/lib/mysql/mysql.sock

[mysqld]
server_id=10
port = 3306
user = mysql
character-set-server = utf8mb4
default_storage_engine = innodb
log_timestamps = SYSTEM
socket = /var/lib/mysql/mysql.sock
basedir = /usr/local/mysql
datadir = /mydata/data
pid-file = /mydata/data/mysql.pid
max_connections = 1000
max_connect_errors = 1000
table_open_cache = 1024
max_allowed_packet = 128M
open_files_limit = 65535
#####====================================[innodb]==============================
innodb_buffer_pool_size = 1024M
innodb_file_per_table = 1
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_purge_threads = 2
innodb_flush_log_at_trx_commit = 1
innodb_log_file_size = 512M
innodb_log_files_in_group = 2
innodb_log_buffer_size = 16M
innodb_max_dirty_pages_pct = 80
innodb_lock_wait_timeout = 30
innodb_data_file_path=ibdata1:1024M:autoextend

#####====================================[log]==============================
log_error = /mydata/log/mysql-error.log 
slow_query_log = 1
long_query_time = 1 
slow_query_log_file = /mydata/log/mysql-slow.log

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

 

初始化数据库

在5.7.6之前初始化的方法是:bin/mysql_install_db --user=mysql

5.7.6之后的版本初始化数据库不再使用mysql_install_db

[root@MySQL mysql]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/mydata/data --innodb_undo_tablespaces=3 --explicit_defaults_for_timestamp
[root@MySQL mysql]# bin/mysql_ssl_rsa_setup --datadir=/mydata/data

 

如果配置了my.cnf的log_error,那么初始密码在log_error文件中,否则会打印出来。


初始完毕之后更改/usr/local/mysql路径下面文件的所属用户

[root@MySQL mysql]# chown -R root .

 

配置启动文件

cp support-files/mysql.server /etc/init.d/mysql
chkconfig --add mysql
chkconfig mysql on
service mysql start

 

配置环境变量

[root@MySQL ~]# vi /etc/profile
mysql_home=/usr/local/mysql
PATH=$PATH:$mysql_home/bin
source /etc/profile


修改密码

在5.7中存储密码的字段不再是password了,变成了authentication_string

update mysql.user set authentication_string=password(‘root‘) where user=‘root‘;
修改root密码后如果第一次使用root用户登入mysql系统还会需要重置一次root密码

SET PASSWORD=PASSWORD(‘root‘);
flush privileges;

 

mysql二进制安装