1.下载5.7.13Generic64位版本软件
[sql] view plain copy
[root@localhost Csong]# ll
total 624872
drwxr-xr-x. 9 7161 wheel 4096 May 25 15:04 mysql-5.7.13-linux-glibc2.5-x86_64
-rw-r--r--. 1 root root 639864682 Aug 3 10:42 mysql-5.7.13-linux-glibc2.5-x86_64.tar.gz
3.用root登入Linux,并创建mysql用户组和mysql用户
[sql] view plain copy
[root@localhost local]# id mysql
uid=27(mysql) gid=27(mysql) groups=27(mysql)
3.解压并拷贝至/usr/local/下,重命名为mysql文件夹,修改mysql文件夹的权限为mysql
[sql] view plain copy
[root@localhost local]# ll
total 4
drwxr-xr-x. 2 root root 6 Aug 12 2015 bin
drwxr-xr-x. 2 root root 6 Aug 12 2015 etc
drwxr-xr-x. 2 root root 6 Aug 12 2015 games
drwxr-xr-x. 2 root root 6 Aug 12 2015 include
drwxr-xr-x. 2 root root 6 Aug 12 2015 lib
drwxr-xr-x. 2 root root 6 Aug 12 2015 lib64
drwxr-xr-x. 2 root root 6 Aug 12 2015 libexec
drwxr-xr-x. 11 mysql mysql 4096 Aug 4 23:05 mysql
drwxr-xr-x. 2 root root 6 Aug 12 2015 sbin
drwxr-xr-x. 5 root root 46 Aug 2 16:18 share
drwxr-xr-x. 2 root root 6 Aug 12 2015 src
[root@localhost local]# cd mysql/
[root@localhost mysql]# ll
total 48
drwxr-xr-x. 2 mysql mysql 4096 Aug 7 06:33 bin
-rw-r--r--. 1 mysql mysql 17987 Aug 3 10:46 COPYING
drwxr-xr-x. 3 mysql mysql 23 Aug 3 10:51 data
drwxr-xr-x. 2 mysql mysql 52 Aug 3 10:47 docs
drwxr-xr-x. 3 mysql mysql 4096 Aug 3 10:47 include
drwxr-xr-x. 5 mysql mysql 4096 Aug 3 10:46 lib
drwxr-xr-x. 4 mysql mysql 28 Aug 3 10:47 man
-rw-r--r--. 1 mysql mysql 2478 Aug 3 10:45 README
drwxr-xr-x. 28 mysql mysql 4096 Aug 3 10:46 share
drwxr-xr-x. 2 mysql mysql 4096 Aug 3 10:46 support-files
4.创建defaults-file文件
这个文件在初始化的时候可以用到,启动的时候也可以用到,你可以改成你想要的任何名字,我这里规定了我的mysql的端口号是3307,并且我单独在根目录下创建了一个给mysql使用的数据目录,并且创建了我的defaults-file,名字为mysql_3307.cnf。
[sql] view plain copy
[root@localhost mysql_3307]# pwd
/data/mysql_3307
[root@localhost mysql_3307]# ll
total 12
drwxr-x---. 5 mysql mysql 4096 Aug 7 07:35 data
drwxr-xr-x. 2 mysql mysql 4096 Aug 7 07:10 logs
-rw-r--r--. 1 mysql mysql 376 Aug 5 14:02 mysql_3307.cnf
drwxr-xr-x. 2 mysql mysql 6 Aug 7 07:10 tmp
[sql] view plain copy
[root@localhost mysql_3307]# cat mysql_3307.cnf
[mysqld]
basedir = /usr/local/mysql/
datadir = /data/mysql_3307/data/
port = 3307
server-id = 2
socket = /tmp/mysql_3307.sock
binlog_format = mixed
gtid-mode = off
#gtid-mode=on ##GTID type
#enforce-gtid-consistency=on ##GTID type
#log_slave_updates ##GTID type
log-bin = /data/mysql_3307/logs/mybinlog
tmpdir = /data/mysql_3307/tmp
log-error = error.log
log-output = file
5.初始化mysqld
[sql] view plain copy
[root@localhost mysql_3307]# /usr/local/mysql/bin/mysqld --defaults-file=/data/mysql_3307/mysql_3307.cnf --initialize --user=mysql
[root@localhost mysql_3307]# /usr/local/mysql/bin/mysql_ssl_rsa_setup --basedir=/usr/local/mysql/ --datadir=/data/mysql_3307/data
Generating a 2048 bit RSA private key
...........................+++
.......................+++
writing new private key to 'ca-key.pem'
Generating a 2048 bit RSA private key
.............+++
...............+++
writing new private key to 'server-key.pem'
Generating a 2048 bit RSA private key
..........+++
................................................................+++
writing new private key to 'client-key.pem'
[root@localhost mysql_3307]# ls data/
auto.cnf client-key.pem ib_logfile0 private_key.pem sys
ca-key.pem error.log ib_logfile1 public_key.pem
ca.pem ib_buffer_pool mysql server-cert.pem
client-cert.pem ibdata1 performance_schema server-key.pem
6.启动mysql实例
[sql] view plain copy
[root@localhost mysql_3307]# /usr/local/mysql/bin/mysqld --defaults-file=/data/mysql_3307/mysql_3307.cnf --user=mysql &
[1] 14452
7.连接mysql
[sql] view plain copy
[root@localhost mysql_3307]# /usr/local/mysql/bin/mysql -S /tmp/mysql_3307.sock -uroot -p
Enter password: --注意,这里的密码,默认mysql会生成一个hash后的初始密码,密码在error.log中,这个error.log的位置在defaults-file中有定义。
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.13-log
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> set password = password('123456'); --注意,最好在登入后,将自己的密码修改一下。
Query OK, 0 rows affected, 1 warning (0.12 sec)
mysql> exit
Bye
[root@localhost mysql_3307]# /usr/local/mysql/bin/mysql -S /tmp/mysql_3307.sock -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.13-log MySQL Community Server (GPL)
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
至此,mysql5.7.13已经安装完毕了。但是,现在mysql中的root用户,远程是登入不了的,因为权限没开放。
可以在mysql命令窗口中输入grant all on . to 'root'@'%' identified by '123456';
这样就可以了。