1、在官网下载安装包:https://dev.mysql.com/downloads/mysql/5.7.html#downloads

       mysql-5.7.10-linux-glibc2.5-x86_64.tar.gz

2、将安装包上传到centos上我安装的目录是在 /usr/local/ 

 1 [root@localhost bin]# cd /
 2 [root@localhost /]# cd usr
 3 [root@localhost usr]# cd local/
 4 [root@localhost local]# ls
 5 bin  etc  games  include  lib  lib64  libexec  sbin  share  src
 6 [root@localhost local]# rz
 7 
 8 [root@localhost local]# ls
 9 bin  etc  games  include  lib  lib64  libexec  mysql-5.7.10-linux-glibc2.5-x86_64.tar.gz  sbin  share  src
10 [root@localhost local]# tar -xzvf mysql-5.7.10-linux-glibc2.5-x86_64.tar.gz 

 

3、将压缩包解压:tar -xzvf mysql-5.7.10...

10 [root@localhost local]# tar -xzvf mysql-5.7.10-linux-glibc2.5-x86_64.tar.gz

 

4、重命名解压后的文件: mv mysql-5.7.10...  mysql

1 [root@localhost local]# ls
2 bin  games    lib    libexec                             mysql-5.7.10-linux-glibc2.5-x86_64.tar.gz  share
3 etc  include  lib64  mysql-5.7.10-linux-glibc2.5-x86_64  sbin                                       src
4 [root@localhost local]# mv mysql-5.7.10-linux-glibc2.5-x86_64 mysql
5 [root@localhost local]# ls
6 bin  etc  games  include  lib  lib64  libexec  mysql  mysql-5.7.10-linux-glibc2.5-x86_64.tar.gz  sbin  share  src

 

5、启动mysql的安装文件

1 [root@localhost mysql]# ./bin/mysql_install_db  --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
2 2017-09-28 11:21:54 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
3 2017-09-28 11:21:59 [WARNING] The bootstrap log isn't empty:
4 2017-09-28 11:21:59 [WARNING] 2017-09-28T03:21:55.455859Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead

注意warning部分:mysql_install_db已经被取代了:

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

6、设置mysql的my.cnf配置 ( 将mysql下的文件复制一份到/etc/目录下 )

cp /usr/local/mysql/support-files/my-default.cnf  /etc/my.cnf

 

7、修改my.cnf里面的内容:

 1 [mysqld]
 2 basedir=/usr/local/mysql
 3 datadir=/usr/local/mysql/data
 4 port=3306
 5 socket=/usr/local/mysql/mysqld.sock
 6 
 7 [client]
 8 default-character-set=utf8
 9 socket=/usr/local/mysql/mysqld.sock
10 
11 [mysql]
12 default-character-set=utf8
13 socket=/usr/local/mysql/mysqld.sock

一开始没有设置mysql的socket,而报

 

1 ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

 

设置好socket 就解决了,其实创建软连接也是不错的选择:ln -s /usr/local/mysql/mysqld.sock  /tmp/mysql.sock

 

 如果mysql启动不了

      拷贝启动文件到/etc/init.d/下并重命令为mysqld

 

1 /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

 

 

8、启动mysql :

[root@localhost etc]# service mysqld restart

 

9、提示修改密码:

1 [root@localhost etc]# mysql
2 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
3 [root@localhost etc]# mysql -uroot -p
4 Enter password: 

10、查看mysql的默认密码:

1 [root@localhost ~]# cat /root/.mysql_secret 
2 # Password set for user 'root@localhost' at 2017-09-28 11:21:55 
3 UQ?x&q+gu#o*

11、用默认密码登录后修改默认密码:

1 mysql> set password = password("root")
2     -> ;
3 Query OK, 0 rows affected, 1 warning (0.00 sec)
4 
5 mysql> flush privileges;
6 Query OK, 0 rows affected (0.00 sec)
7 
8 mysql> use mysql

然后就可以自己对数据库进行相应的操作了。

12、开启远程连接

 

mysql> select host,user ,password from user;
+-----------------------+------+-------------------------------------------+
| host                  | user | password                                  |
+-----------------------+------+-------------------------------------------+
| %                     | root | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |
| localhost.localdomain | root |                                           |
| 127.0.0.1             | root |                                           |
| ::1                   | root |                                           |
| localhost             |      |                                           |
| localhost.localdomain |      |                                           |
+-----------------------+------+-------------------------------------------+

 

 

mysql>  update user set host = '%' where user = 'root';
mysql>  grant all privileges  on *.* to root@'%' identified by "password" with grant option;
mysql> flush privileges;

如果需要指定特定的ip地址,可以直接用grant all privileges on *.* to root@'ip' identified by "password" with grant option;

 

问题总结:

一、 Starting MySQL.The server quit without updating PID file (/[FAILED]l/mysql/data/mysql.pid).

网上说了很多但都不是自己出现的

Google了下 ,问题可能的原因有多种,具体什么原因最好的办法是先查看下错误日志:
1、可能是/usr/local/mysql/data/mysql.pid文件没有写的权限
解决方法 :给予权限,执行 “chown -R mysql:mysql /var/data” “chmod -R 755 /usr/local/mysql/data”  然后重新启动mysqld!

2、可能进程里已经存在mysql进程
解决方法:用命令“ps -ef|grep mysqld”查看是否有mysqld进程,如果有使用“kill -9  进程号”杀死,然后重新启动mysqld!

3、可能是第二次在机器上安装mysql,有残余数据影响了服务的启动。
解决方法:去mysql的数据目录/data看看,如果存在mysql-bin.index,就赶快把它删除掉吧,它就是罪魁祸首了。本人就是使用第三条方法解决的 !

4、mysql在启动时没有指定配置文件时会使用/etc/my.cnf配置文件,请打开这个文件查看在[mysqld]节下有没有指定数据目录(datadir)。
解决方法:请在[mysqld]下设置这一行:datadir = /usr/local/mysql/data

5、skip-federated字段问题
解决方法:检查一下/etc/my.cnf文件中有没有没被注释掉的skip-federated字段,如果有就立即注释掉吧。

6、错误日志目录不存在
解决方法:使用“chown” “chmod”命令赋予mysql所有者及权限

7、selinux惹的祸,如果是centos系统,默认会开启selinux
解决方法:关闭它,打开/etc/selinux/config,把SELINUX=enforcing改为SELINUX=disabled后存盘退出重启机器试试。

8、[ERROR] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root

解决方法:在/mysql/my.cnf文件中,指定user=mysql  或强制使用root启动  mysqld --user=root

9、 [Note] Plugin 'FEDERATED' is disabled../mysqld: Table 'mysql.plugin' doesn't exist

[ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.

解决方法:./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

自己问题解决方式:

10、本地root用户连接问题Access denied for user 'root'@'localhost' (using password: YES)

解决方法:授权root用户权限      grant all privileges on *.* to 'root'@'localhost' identified by 'root' with grant option;

/etc/my.cnf的配置文件参数少了或者错误

一份正确的配置参数:

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.

#[mysqld]

# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin

# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....
# socket = .....
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
port=3306
user=mysql socket=/usr/local/mysql/mysqld.sock log-bin=mysql-bin server-id=1 pid-file = /usr/local/mysql/data/
mysql.pid port=3306 socket=/usr/local/mysql/mysqld.sock log-bin=mysql-bin server-id=1 pid-file = /usr/local/mysql/data/mysql.pid binlog_format=row binlog-row-image = full max_binlog_size =128M binlog_cache_size =2M expire_logs_days =7 [client] default-character-set=utf8 socket=/usr/local/mysql/mysqld.sock #[mysql] #default-character-set=utf8 #socket=/usr/local/mysql/mysqld.sock # Remove leading # to set options mainly useful for reporting servers. # The server defaults are faster for transactions and fast SELECTs. # Adjust sizes as needed, experiment to find the optimal values. # join_buffer_size = 128M # sort_buffer_size = 2M # read_rnd_buffer_size = 2M #sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

 

 

[Reference]

[1] http://www.jb51.net/article/117722.htm