一、在线安装
[root@test sunji]# rpm -qa | grep mysql
mysql-libs-5.1.73-8.el6_8.x86_64
[root@test sunji]# yum install -y wget
已加载插件:fastestmirror, refresh-packagekit,security
设置安装进程
Loading mirror speeds from cached hostfile
*local:
包 wget-1.12-10.el6.x86_64 已安装并且是最新版本
无须任何处理
[root@test sunji]#
登录Mysql官网àDocumentationàMySql ServeràInstalling andUpgrading MySQL
à2.5 Installing MySQL on Linuxà2.5.1 Installing MySQL on LinuxUsing the MySQL Yum Repository
à找到Adding the MySQL Yum Repository下面的超链接à在新页面打开à找到自己linux对应版本[孙寄1]
àNo thanks, just start my download.右键à复制链接地址用于wget…
[root@testsunji]# wgethttps://dev.mysql.com/get/mysql57-community-release-el6-11.noarch.rpm
--2017-09-09 11:10:22-- https://dev.mysql.com/get/mysql57-community-release-el6-11.noarch.rpm
正在解析主机 dev.mysql.com... 137.254.60.11
正在连接 dev.mysql.com|137.254.60.11|:443... 已连接。
已发出 HTTP 请求,正在等待回应...302 Found
位置:https://repo.mysql.com//mysql57-community-release-el6-11.noarch.rpm[跟随至新的 URL]
--2017-09-09 11:10:25-- https://repo.mysql.com//mysql57-community-release-el6-11.noarch.rpm
正在解析主机 repo.mysql.com... 104.127.195.16
正在连接 repo.mysql.com|104.127.195.16|:443... 已连接。
已发出 HTTP 请求,正在等待回应...200 OK
长度:25664 (25K)[application/x-redhat-package-manager]
正在保存至:“mysql57-community-release-el6-11.noarch.rpm”
100%[======================================================================================================================================>]25,664 --.-K/s in 0.1s
2017-09-09 11:10:26 (188 KB/s) - 已保存 “mysql57-community-release-el6-11.noarch.rpm” [25664/25664])
[root@test sunji]# yum localinstallmysql57-community-release-el6-11.noarch.rpm
已加载插件:fastestmirror, refresh-packagekit,security
设置本地安装进程
诊断mysql57-community-release-el6-11.noarch.rpm:mysql57-community-release-el6-11.noarch
mysql57-community-release-el6-11.noarch.rpm将被安装
Loading mirror speeds from cached hostfile
*local:
解决依赖关系
--> 执行事务检查
---> Packagemysql57-community-release.noarch 0:el6-11 will be 安装
--> 完成依赖关系计算
依赖关系解决
================================================================================
软件包 架构 版本 仓库 大小
================================================================================
正在安装:
mysql57-community-release
noarch el6-11/mysql57-community-release-el6-11.noarch 31 k
事务概要
================================================================================
Install 1 Package(s)
总文件大小:31 k
Installed size: 31 k
确定吗?[y/N]:y
下载软件包:
运行 rpm_check_debug
执行事务测试
事务测试成功
执行事务
正在安装 :mysql57-community-release-el6-11.noarch 1/1
Verifying :mysql57-community-release-el6-11.noarch 1/1
已安装:
mysql57-community-release.noarch 0:el6-11
完毕!
[root@test sunji]# yum repolist enabled | grep"mysql.*-community.*"
mysql-connectors-community MySQL Connectors Community 42
mysql-tools-community MySQL Tools Community 51
mysql57-community MySQL 5.7 Community Server 201
[root@test sunji]#
[root@test sunji]# yum repolist all | grep mysql
mysql-cluster-7.5-community MySQL Cluster 7.5 Community 禁用
mysql-cluster-7.5-community-source MySQLCluster 7.5 Community - Sou 禁用
mysql-cluster-7.6-community MySQL Cluster 7.6 Community 禁用
mysql-cluster-7.6-community-source MySQLCluster 7.6 Community - Sou 禁用
mysql-connectors-community MySQL Connectors Community 启用: 42
mysql-connectors-community-source MySQL Connectors Community - Sour 禁用
mysql-tools-community MySQL Tools Community 启用: 51
mysql-tools-community-source MySQL Tools Community - Source 禁用
mysql-tools-preview MySQL Tools Preview 禁用
mysql-tools-preview-source MySQL Tools Preview - Source 禁用
mysql55-community MySQL 5.5 CommunityServer 禁用
mysql55-community-source MySQL 5.5 Community Server - Sour 禁用
mysql56-community MySQL 5.6 Community Server 禁用
mysql56-community-source MySQL 5.6 Community Server - Sour 禁用
mysql57-community MySQL 5.7 CommunityServer 启用: 201
mysql57-community-source MySQL 5.7 Community Server - Sour 禁用
mysql80-community MySQL 8.0 CommunityServer 禁用
mysql80-community-source MySQL 8.0 Community Server - Sour 禁用
[root@test sunji]#
[root@test sunji]# yum install mysql-community-server
已加载插件:fastestmirror, refresh-packagekit,security
设置安装进程
Loading mirror speeds from cached hostfile
*local:
解决依赖关系
--> 执行事务检查
---> Packagemysql-community-server.x86_64 0:5.7.19-1.el6 will be 安装
--> 处理依赖关系mysql-community-common(x86-64) = 5.7.19-1.el6,它被软件包 mysql-community-server-5.7.19-1.el6.x86_64需要
--> 处理依赖关系mysql-community-client(x86-64) >= 5.7.9,它被软件包mysql-community-server-5.7.19-1.el6.x86_64 需要
--> 执行事务检查
---> Packagemysql-community-client.x86_64 0:5.7.19-1.el6 will be 安装
--> 处理依赖关系mysql-community-libs(x86-64) >= 5.7.9,它被软件包mysql-community-client-5.7.19-1.el6.x86_64 需要
---> Packagemysql-community-common.x86_64 0:5.7.19-1.el6 will be 安装
--> 执行事务检查
---> Package mysql-community-libs.x86_640:5.7.19-1.el6 will be obsoleting
---> Package mysql-libs.x86_640:5.1.73-8.el6_8 will be 取代
--> 处理依赖关系libmysqlclient.so.16()(64bit),它被软件包2:postfix-2.6.6-8.el6.x86_64 需要
--> 处理依赖关系libmysqlclient.so.16(libmysqlclient_16)(64bit),它被软件包2:postfix-2.6.6-8.el6.x86_64 需要
--> 执行事务检查
---> Package mysql-community-libs-compat.x86_640:5.7.19-1.el6 will be obsoleting
--> 完成依赖关系计算
依赖关系解决
====================================================================================================================
软件包 架构 版本 仓库 大小
====================================================================================================================
正在安装:
mysql-community-libs x86_64 5.7.19-1.el6 mysql57-community 2.1 M
replacing mysql-libs.x86_645.1.73-8.el6_8
mysql-community-libs-compat x86_64 5.7.19-1.el6 mysql57-community 1.6 M
replacing mysql-libs.x86_645.1.73-8.el6_8
mysql-community-server x86_64 5.7.19-1.el6 mysql57-community 152 M
为依赖而安装:
mysql-community-client x86_64 5.7.19-1.el6 mysql57-community 23 M
mysql-community-common x86_64 5.7.19-1.el6 mysql57-community 328 k
事务概要
====================================================================================================================
Install 5 Package(s)
总下载量:179 M
确定吗?[y/N]:y
下载软件包:
(1/5):mysql-community-client-5.7.19-1.el6.x86_64.rpm | 23 MB 09:23
(2/5):mysql-community-common-5.7.19-1.el6.x86_64.rpm | 328kB 00:07
(3/5):mysql-community-libs-5.7.19-1.el6.x86_64.rpm | 2.1MB 00:42
(4/5):mysql-community-libs-compat-5.7.19-1.el6.x86_64.rpm | 1.6MB 00:31
(5/5): mysql-community-server-5.7.19-1.el6.x86_64.rpm | 152 MB 54:48
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
总计 47 kB/s | 179 MB 65:34
warning: rpmts_HdrFromFdno: Header V3DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Retrieving key fromfile:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Importing GPG key 0x5072E1F5:
Userid : MySQL Release Engineering<mysql-build@oss.oracle.com>
Package: mysql57-community-release-el6-11.noarch(@/mysql57-community-release-el6-11.noarch)
From :/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
确定吗?[y/N]:y
运行 rpm_check_debug
执行事务测试
事务测试成功
执行事务
正在安装 :mysql-community-common-5.7.19-1.el6.x86_64 1/6
正在安装 :mysql-community-libs-5.7.19-1.el6.x86_64 2/6
正在安装 :mysql-community-client-5.7.19-1.el6.x86_64 3/6
正在安装 :mysql-community-server-5.7.19-1.el6.x86_64 4/6
正在安装 :mysql-community-libs-compat-5.7.19-1.el6.x86_64 5/6
正在删除 :mysql-libs-5.1.73-8.el6_8.x86_64 6/6
Verifying :mysql-community-server-5.7.19-1.el6.x86_64 1/6
Verifying :mysql-community-common-5.7.19-1.el6.x86_64 2/6
Verifying :mysql-community-libs-compat-5.7.19-1.el6.x86_64 3/6
Verifying :mysql-community-libs-5.7.19-1.el6.x86_64 4/6
Verifying :mysql-community-client-5.7.19-1.el6.x86_64 5/6
Verifying :mysql-libs-5.1.73-8.el6_8.x86_64 6/6
已安装:
mysql-community-libs.x86_64 0:5.7.19-1.el6 mysql-community-libs-compat.x86_640:5.7.19-1.el6 mysql-community-server.x86_64 0:5.7.19-1.el6
作为依赖被安装:
mysql-community-client.x86_64 0:5.7.19-1.el6 mysql-community-common.x86_64 0:5.7.19-1.el6
替代:
mysql-libs.x86_64 0:5.1.73-8.el6_8
完毕!
[root@test sunji]# service mysqld start
初始化 MySQL 数据库: [确定]
正在启动 mysqld: [确定]
[root@test sunji]# ps -ef|grep mysql
root 2624 1 0 12:54 pts/0 00:00:00 /bin/sh /usr/bin/mysqld_safe--datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock--pid-file=/var/run/mysqld/mysqld.pid --basedir=/usr --user=mysql
mysql 2818 2624 2 12:54 pts/0 00:00:00 /usr/sbin/mysqld --basedir=/usr--datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql--log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid--socket=/var/lib/mysql/mysql.sock
root 2854 2201 0 12:55 pts/0 00:00:00 grep mysql
[root@test sunji]# service mysqld status
mysqld (pid 2818) 正在运行...
[root@test sunji]# grep 'temporary password' /var/log/mysqld.log
2017-09-09T04:54:51.710581Z 1 [Note] Atemporary password is generated for root@localhost:NftSGDwiY4,I
[root@test sunji]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.19
Copyright (c) 2000, 2017, Oracle and/or itsaffiliates. All rights reserved.
Oracle is a registered trademark of OracleCorporation and/or its
affiliates. Other names may be trademarksof their respective
owners.
Type 'help;' or '\h' for help. Type '\c' toclear the current input statement.
mysql> show databases;
ERROR 1820 (HY000): You must reset yourpassword using ALTER USER statement before executing this statement.
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY ' NftSGDwiY4,I ';
Query OK, 0 rows affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql> use mysql
Reading table information for completion oftable and column names
You can turn off this feature to get aquicker startup with -A
Database changed
mysql>
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> select user,host from user;
+---------------+-----------+
| user | host |
+---------------+-----------+
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+---------------+-----------+
3 rows in set (0.00 sec)
mysql> exit;
Bye
[root@test sunji]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.19 MySQL CommunityServer (GPL)
Copyright (c) 2000, 2017, Oracle and/or itsaffiliates. All rights reserved.
Oracle is a registered trademark of OracleCorporation and/or its
affiliates. Other names may be trademarksof their respective
owners.
Type 'help;' or '\h' for help. Type '\c' toclear the current input statement.
-----------------------------------------------------------------------------------------------------------------------------------------------
二、修改密码
修改mysql5.7.19 root密码
1. 把mysql停止。
$ sudo service mysqld stop
[ ok ] Stopping mysql (via systemctl): mysql.service.
2. 启动mysqld_safe。
$ sudo mysqld_safe--skip-grant-tables &
[1] 28860
(如果遇到错误
mysqld_safeDirectory '/var/run/mysqld' for UNIX socket file don't exists.
则执行下面命令后再次启动mysqld_safe。
sudomkdir -p /var/run/mysqld
sudochown mysql:mysql /var/run/mysqld
)
3. 克隆一个会话,进入mysql,执行两条命令:
$ mysql -u root
mysql>UPDATE mysql.user SETauthentication_string = PASSWORD('root') , password_expired = 'N' WHERE User ='root' AND Host = 'localhost';
Query OK, 0 rows affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 1
mysql>use mysql;
mysql>update user setplugin="mysql_native_password";
Query OK, 1 row affected (0.00 sec)
Rows matched: 3 Changed: 1 Warnings: 0
注意Mysql5.7版本要修改的字段为authentication_string,而不是Password。另外,plugin字段的值要置成"mysql_native_password"。
4. 退出mysql
mysql>quit;
Bye
5. 停止Mysql
$ sudo service mysqld stop
[ ok ] Stopping mysql (via systemctl): mysql.service.
$ sudo kill -9 $(pgrep mysql)
6. 再次启动mysql
$ sudo service mysqld start
[ ok ] Starting mysql (via systemctl): mysql.service.
再次用密码可以登录。
$ mysql -uroot -p
Enter password: root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.19 MySQL Community Server (GPL)
--------------------------------------------------------------------------------------------------------------------
三、设置可以远程访问
登录mysql
mysql -uroot -proot
set global validate_password_policy=0;
set global validate_password_length=4;
#(执行下面的语句 *.*:所有库下的所有表 %:任何IP地址或主机都可以连接)
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITHGRANT OPTION;
FLUSH PRIVILEGES;
[孙寄1]查看linux内核版本的命令
方法一:
命令: uname -a
作用: 查看系统内核版本号及系统名称
方法二:
命令: cat /proc/version
作用: 查看目录"/proc"下version的信息,也可以得到当前系统的内核版本号及系统名称