下载MySql5.7
[root@localhost ~]# cd /home
[root@localhost ~]#wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.22-1.el7.x86_64.rpm-bundle.tar
解压
[root@localhost ~]#tar -xvf mysql-5.7.22-1.el7.x86_64.rpm-bundle.tar
[root@localhost home]# ls
gren  mysql-5.7.22-1.el7.x86_64.rpm-bundle  mysql-community-server-5.7.22-1.el7.x86_64.rpm
[root@localhost home]# cd mysql-5.7.22-1.el7.x86_64.rpm-bundle/
[root@localhost mysql-5.7.22-1.el7.x86_64.rpm-bundle]# ls
mysql-community-client-5.7.22-1.el7.x86_64.rpm    mysql-community-embedded-devel-5.7.22-1.el7.x86_64.rpm     mysql-community-server-5.7.22-1.el7.x86_64.rpm
mysql-community-common-5.7.22-1.el7.x86_64.rpm    mysql-community-libs-5.7.22-1.el7.x86_64.rpm               mysql-community-server-minimal-5.7.22-1.el7.x86_64.rpm
mysql-community-devel-5.7.22-1.el7.x86_64.rpm     mysql-community-libs-compat-5.7.22-1.el7.x86_64.rpm        mysql-community-test-5.7.22-1.el7.x86_64.rpm
mysql-community-embedded-5.7.22-1.el7.x86_64.rpm  mysql-community-minimal-debuginfo-5.7.22-1.el7.x86_64.rpm
[root@localhost mysql-5.7.22-1.el7.x86_64.rpm-bundle]# rpm -qa|grep mariadb
mariadb-libs-5.5.52-1.el7.x86_64
[root@localhost mysql-5.7.22-1.el7.x86_64.rpm-bundle]# rpm -e --nodeps mariadb-libs
警告:/etc/my.cnf 已另存为 /etc/my.cnf.rpmsave
[root@localhost mysql-5.7.22-1.el7.x86_64.rpm-bundle]# rpm -ivh mysql-community-common-5.7.22-1.el7.x86_64.rpm
警告:mysql-community-common-5.7.22-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql-community-common-5.7.22-1.e################################# [100%]
[root@localhost mysql-5.7.22-1.el7.x86_64.rpm-bundle]# rpm -ivh mysql-community-libs-5.7.22-1.el7.x86_64.rpm
警告:mysql-community-libs-5.7.22-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql-community-libs-5.7.22-1.el7################################# [100%]
[root@localhost mysql-5.7.22-1.el7.x86_64.rpm-bundle]# rpm -ivh mysql-community-embedded-5.7.22-1.el7.x86_64.rpm
警告:mysql-community-embedded-5.7.22-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql-community-embedded-5.7.22-1################################# [100%]
[root@localhost mysql-5.7.22-1.el7.x86_64.rpm-bundle]# rpm -ivh mysql-community-client-5.7.22-1.el7.x86_64.rpm
警告:mysql-community-client-5.7.22-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql-community-client-5.7.22-1.e################################# [100%]
[root@localhost mysql-5.7.22-1.el7.x86_64.rpm-bundle]# rpm -ivh mysql-community-server-5.7.22-1.el7.x86_64.rpm
警告:mysql-community-server-5.7.22-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql-community-server-5.7.22-1.e################################# [100%]
[root@localhost init.d]# systemctl start mysqld
[root@localhost init.d]# ps aux|grep mysqld
mysql    44858  3.8  1.0 1119408 170916 ?      Sl   17:14   0:00 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
root     44887  0.0  0.0 112664   968 pts/2    S+   17:14   0:00 grep --color=auto mysqld
[root@localhost init.d]# netstat -nlt
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State     
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN    
tcp        0      0 192.168.122.1:53        0.0.0.0:*               LISTEN    
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN    
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN    
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN    
tcp6       0      0 :::3306                 :::*                    LISTEN    
tcp6       0      0 :::111                  :::*                    LISTEN    
tcp6       0      0 :::22                   :::*                    LISTEN    
tcp6       0      0 ::1:631                 :::*                    LISTEN    
tcp6       0      0 ::1:25                  :::*                    LISTEN    
[root@localhost init.d]# mysql -uroot -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@localhost init.d]# mysql -uroot -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@localhost init.d]# cd /etc/my.cnf.d/
[root@localhost my.cnf.d]# ls
[root@localhost my.cnf.d]# cd ..
[root@localhost etc]# ls
abrt                       cron.d                      firefox             inputrc         mail.rc                   pcp.conf          rpc                sysconfig
adjtime                    cron.daily                  firewalld           ipa             makedumpfile.conf.sample  pcp.env           rpm                sysctl.conf
aliases                    cron.deny                   fonts               iproute2        man_db.conf               pinforc           rsyncd.conf        sysctl.d
aliases.db                 cron.hourly                 fprintd.conf        ipsec.conf      maven                     pkcs11            rsyslog.conf       systemd
alsa                       cron.monthly                fstab               ipsec.d         mime.types                pki               rsyslog.d          system-release
alternatives               crontab                     fuse.conf           ipsec.secrets   mke2fs.conf               plymouth          rwtab              system-release-cpe
anacrontab                 cron.weekly                 gconf               iscsi           modprobe.d                pm                rwtab.d            target
asound.conf                crypttab                    gcrypt              issue           modules-load.d            pnm2ppa.conf      samba              tcsd.conf
at.deny                    csh.cshrc                   gdbinit             issue.net       motd                      polkit-1          sane.d             terminfo
at-spi2                    csh.login                   gdbinit.d           java            mtab                      popt.d            sasl2              tmpfiles.d
audisp                     cups                        gdm                 jvm             mtools.conf               postfix           scl                trusted-key.key
audit                      cupshelpers                 geoclue             jvm-commmon     multipath                 ppp               securetty          tuned
autofs.conf                dbus-1                      GeoIP.conf          kdump.conf      my.cnf                    prelink.conf.d    security           udev
autofs_ldap_auth.conf      dconf                       GeoIP.conf.default  kernel          my.cnf.d                  printcap          selinux            udisks2
auto.master                default                     ghostscript         krb5.conf       my.cnf.rpmsave            profile           services           unbound
auto.master.d              depmod.d                    gnupg               krb5.conf.d     nanorc                    profile.d         sestatus.conf      updatedb.conf
auto.misc                  dhcp                        GREP_COLORS         ksmtuned.conf   netconfig                 protocols         setroubleshoot     UPower
auto.net                   DIR_COLORS                  groff               latrace.d       NetworkManager            pulse             setuptool.d        usb_modeswitch.conf
auto.smb                   DIR_COLORS.256color         group               ld.so.cache     networks                  purple            sgml               vconsole.conf
avahi                      DIR_COLORS.lightbgcolor     group-              ld.so.conf      nfsmount.conf             python            shadow             vimrc
bash_completion.d          dleyna-server-service.conf  grub2.cfg           ld.so.conf.d    nsswitch.conf             qemu-ga           shadow-            virc
bashrc                     dnsmasq.conf                grub.d              libaudit.conf   nsswitch.conf.bak         qemu-kvm          shells             vmware-tools
binfmt.d                   dnsmasq.d                   gshadow             libibverbs.d    ntp                       radvd.conf        skel               wgetrc
bluetooth                  dracut.conf                 gshadow-            libnl           ntp.conf                  rc0.d             smartmontools      wpa_supplicant
brltty                     dracut.conf.d               gss                 libreport       numad.conf                rc1.d             sos.conf           wvdial.conf
brltty.conf                drirc                       gssproxy            libuser.conf    oddjob                    rc2.d             speech-dispatcher  X11
centos-release             e2fsck.conf                 highlight           libvirt         oddjobd.conf              rc3.d             ssh                xdg
centos-release-upstream    enscript.cfg                host.conf           locale.conf     oddjobd.conf.d            rc4.d             ssl                xinetd.d
certmonger                 environment                 hostname            localtime       openldap                  rc5.d             sssd               xml
cgconfig.conf              ethertypes                  hosts               login.defs      opt                       rc6.d             statetab           yum
cgconfig.d                 exports                     hosts.allow         logrotate.conf  os-release                rc.d              statetab.d         yum.conf
cgrules.conf               exports.d                   hosts.deny          logrotate.d     PackageKit                rc.local          subgid             yum.repos.d
cgsnapshot_blacklist.conf  extlinux.conf               hp                  lsm             pam.d                     rdma              subuid
chkconfig.d                favicon.png                 httpd               lvm             passwd                    redhat-release    sudo.conf
chrony.conf                fcoe                        idmapd.conf         machine-id      passwd-                   request-key.conf  sudoers
chrony.keys                festival                    init.d              magic           pbm2ppa.conf              request-key.d     sudoers.d
cifs-utils                 filesystems                 inittab             mailcap         pcp                       resolv.conf       sudo-ldap.conf
#接下来加入一句代码即可空密码登录mysql:
# Disabling symbolic-links is recommended to prevent assorted security risks
skip-grant-tables     #添加这句话,这时候登入mysql就不需要密码
symbolic-links=0

[root@localhost etc]# nano my.cnf
[root@localhost etc]# systemctl stop mysqld
[root@localhost etc]# systemctl start mysqld
[root@localhost etc]# mysql -uroot -p
Enter password: 直接回车
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.22 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, 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> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> set password for root@localhost = password('root');
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> exit
Bye

vim /etc/my.cnf     #修改配置文件
# Disabling symbolic-links is recommended to prevent assorted security risks
# skip-grant-tables # 注释掉这句话
symbolic-links=0

symbolic-links=0
[root@localhost etc]# nano my.cnf
[root@localhost etc]# systemctl stop mysqld
[root@localhost etc]# systemctl start mysqld
[root@localhost etc]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.22 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, 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> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables
    -> ;
+---------------------------+
| Tables_in_mysql           |
+---------------------------+
| columns_priv              |
| db                        |
| engine_cost               |
| event                     |
| func                      |
| general_log               |
| gtid_executed             |
| help_category             |
| help_keyword              |
| help_relation             |
| help_topic                |
| innodb_index_stats        |
| innodb_table_stats        |
| ndb_binlog_index          |
| plugin                    |
| proc                      |
| procs_priv                |
| proxies_priv              |
| server_cost               |
| servers                   |
| slave_master_info         |
| slave_relay_log_info      |
| slave_worker_info         |
| slow_log                  |
| tables_priv               |
| time_zone                 |
| time_zone_leap_second     |
| time_zone_name            |
| time_zone_transition      |
| time_zone_transition_type |
| user                      |
+---------------------------+
31 rows in set (0.00 sec)

mysql> selet * from user;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'selet * from user' at line 1
mysql> selet * from 'user';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'selet * from 'user'' at line 1
mysql> select * from 'user';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''user'' at line 1
mysql> select * from user;
+-----------+---------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+------------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+-----------------------+-------------------------------------------+------------------+-----------------------+-------------------+----------------+
| Host      | User          | Select_priv | Insert_priv | Update_priv | Delete_priv | Create_priv | Drop_priv | Reload_priv | Shutdown_priv | Process_priv | File_priv | Grant_priv | References_priv | Index_priv | Alter_priv | Show_db_priv | Super_priv | Create_tmp_table_priv | Lock_tables_priv | Execute_priv | Repl_slave_priv | Repl_client_priv | Create_view_priv | Show_view_priv | Create_routine_priv | Alter_routine_priv | Create_user_priv | Event_priv | Trigger_priv | Create_tablespace_priv | ssl_type | ssl_cipher | x509_issuer | x509_subject | max_questions | max_updates | max_connections | max_user_connections | plugin                | authentication_string                     | password_expired | password_last_changed | password_lifetime | account_locked |
+-----------+---------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+------------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+-----------------------+-------------------------------------------+------------------+-----------------------+-------------------+----------------+
| localhost | root          | Y           | Y           | Y           | Y           | Y           | Y         | Y           | Y             | Y            | Y         | Y          | Y               | Y          | Y          | Y            | Y          | Y                     | Y                | Y            | Y               | Y                | Y                | Y              | Y                   | Y                  | Y                | Y          | Y            | Y                      |          |            |             |              |             0 |           0 |               0 |                    0 | mysql_native_password | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B | N                | 2018-05-11 17:21:04   |              NULL | N              |
| localhost | mysql.session | N           | N           | N           | N           | N           | N         | N           | N             | N            | N         | N          | N               | N          | N          | N            | Y          | N                     | N                | N            | N               | N                | N                | N              | N                   | N                  | N                | N          | N            | N                      |          |            |             |              |             0 |           0 |               0 |                    0 | mysql_native_password | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | N                | 2018-05-11 17:14:15   |              NULL | Y              |
| localhost | mysql.sys     | N           | N           | N           | N           | N           | N         | N           | N             | N            | N         | N          | N               | N          | N          | N            | N          | N                     | N                | N            | N               | N                | N                | N              | N                   | N                  | N                | N          | N            | N                      |          |            |             |              |             0 |           0 |               0 |                    0 | mysql_native_password | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | N                | 2018-05-11 17:14:15   |              NULL | Y              |
+-----------+---------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+------------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+-----------------------+-------------------------------------------+------------------+-----------------------+-------------------+----------------+
3 rows in set (0.00 sec)

mysql> update user set Host='%' where User='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> flush privileges
    -> ;
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye
[root@localhost etc]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
success
[root@localhost etc]# firewall-cmd --reload
success
[root@localhost etc]# systemctl enable mysqld
[root@localhost etc]# chkconfig --list

注意:该输出结果只显示 SysV 服务,并不包含原生 systemd 服务。SysV 配置数据可能被原生 systemd 配置覆盖。
      如果您想列出 systemd 服务,请执行 'systemctl list-unit-files'。
      欲查看对特定 target 启用的服务请执行
      'systemctl list-dependencies [target]'。

netconsole      0:关 1:关 2:关 3:关 4:关 5:关 6:关
network         0:关 1:关 2:开 3:开 4:开 5:开 6:关
[root@localhost etc]# systemctl daemon-reload
[root@localhost etc]# chkconfig --list

注意:该输出结果只显示 SysV 服务,并不包含原生 systemd 服务。SysV 配置数据可能被原生 systemd 配置覆盖。
      如果您想列出 systemd 服务,请执行 'systemctl list-unit-files'。
      欲查看对特定 target 启用的服务请执行
      'systemctl list-dependencies [target]'。

netconsole      0:关 1:关 2:关 3:关 4:关 5:关 6:关
network         0:关 1:关 2:开 3:开 4:开 5:开 6:关
[root@localhost etc]# chkconfig --add /etc/init.d/mysql
mysql         mysql.server 
[root@localhost etc]# chkconfig --add /etc/init.d/mysql
[root@localhost etc]# chkconfig --list

注意:该输出结果只显示 SysV 服务,并不包含原生 systemd 服务。SysV 配置数据可能被原生 systemd 配置覆盖。
      如果您想列出 systemd 服务,请执行 'systemctl list-unit-files'。
      欲查看对特定 target 启用的服务请执行
      'systemctl list-dependencies [target]'。

mysql           0:关 1:关 2:开 3:开 4:开 5:开 6:关
netconsole      0:关 1:关 2:关 3:关 4:关 5:关 6:关
network         0:关 1:关 2:开 3:开 4:开 5:开 6:关
[root@localhost etc]#



注意:本文归作者所有,未经作者允许,不得转载