安装:MySQL mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz

1、下载mysql-5.7.19源码包(不需要编译):

$ wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz

2、我们需要新建一个mysql组

$ sudo groupadd mysql

3、新建一个mysql用户加入该组

$ sudo useradd -r -g mysql mysql

4、解压缩

$ tar -zxvf mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz

5、将解压之后的文件改名为mysql 放到 /opt下边

$ mv mysql-5.7.19-linux-glibc2.12-x86_64 /opt/mysql

6、进入到/opt/mysql目录下更改权限

$ chown -R mysql . //将当前目录的拥有者权限更改为mysql
$ chgrp -R mysql . //将当前的目录的组权限更改为mysql组

7、安装辅助的库文件,当然不是必须的看你系统中是不是有

$ sudo apt-get intall libaio1

8、在/etc目录下创建文件my.cnf,并且填写设置内容

$ cd /etc
$ touch my.cnf
$ vi my.cnf
[mysqld]
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
explicit_defaults_for_timestamp=true
basedir = /opt/mysql
datadir = /data/mysql
port = 3306
socket = /opt/mysql/mysqld/mysql.sock
pid-file = /opt/mysql/mysqld/mysql.pid
character-set-server=utf8
back_log = 300
max_connections = 3000
max_connect_errors = 50
table_open_cache = 4096
max_allowed_packet = 32M
max_heap_table_size = 128M
read_rnd_buffer_size = 16M
sort_buffer_size = 16M
join_buffer_size = 16M
thread_cache_size = 16
query_cache_size = 128M
query_cache_limit = 4M
ft_min_word_len = 8
thread_stack = 512K
transaction_isolation = REPEATABLE-READ
tmp_table_size = 128M
long_query_time = 6
server_id=1
innodb_buffer_pool_size = 1G
innodb_thread_concurrency = 16
innodb_log_buffer_size = 16M
innodb_log_file_size = 512M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
innodb_file_per_table = on
[mysqldump]
quick
max_allowed_packet = 32M
[mysql]
no-auto-rehash
default-character-set=utf8
safe-updates
[myisamchk]
key_buffer = 16M
sort_buffer_size = 16M
read_buffer = 8M
write_buffer = 8M
[mysqlhotcopy]
interactive-timeout
[mysqld_safe]
open-files-limit = 8192
[client]
port = 3306
socket = /opt/mysql/mysqld/mysql.sock
default-character-set = utf8

9、创建文件夹/data/mysql,/opt/mysql/mysqld

$ mkdir -p /data/mysql
$ chown -R mysql:mysql /data/mysql
$ chmod -R 755 /data/mysql
$ mkdir -p /opt/mysql/mysqld
$ chown -R mysql:mysql /opt/mysql/mysqld
$ chmod -R 755 /opt/mysql/mysqld

10、到解压的mysql目录中找到bin ,在bin中有 mysqld 可执行文件。执行

$ ./mysqld --user=mysql --basedir=/opt/mysql --datadir=/data/mysql --initialize

2017-07-31T16:59:21.450195Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-07-31T16:59:21.990321Z 0 [Warning] InnoDB: New log files created, LSN=45790
2017-07-31T16:59:22.084681Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2017-07-31T16:59:22.150650Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 99984cd2-7611-11e7-9025-58946bfd7c3c.
2017-07-31T16:59:22.153325Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2017-07-31T16:59:22.154050Z 1 [Note] A temporary password is generated for root@localhost: dsuIequSe5>E

由上面信息可得:dsuIequSe5>E (为root用户的临时登录密码)

11、创建链接

$ ln -fs /opt/mysql/bin/mysql /usr/local/bin/mysql
$ cp /opt/mysql/support-files/mysql.server /etc/init.d/mysqld

12、配置系统环境变量
MYSQL_HOME=/opt/mysql/bin
PATH=$MYSQL_HOME/bin:$PATH
export MYSQL_HOME

12、启动MySQL服务

$ /etc/init.d/mysqld start
或者 进入MySQL安装目录/opt/mysql/bin文件夹中,执行下面的命令
$ ./mysqld_safe --user=mysql &
我的启动服务方式:systemctl start mysql
PS:如果启动、停止服务失败的话,重启系统,在启动mysql服务

13、登录MySQL数据库

$ mysql --user=root -p
密码:步骤10中生成的零时密码
mysql> set password=password('Aber');

Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> grant all privileges on × to root@'%' identified by 'password';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

你可能感兴趣的:(安装:MySQL mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz)