CentOS7安装MySQL5.7以及修改密码
CentOS7安装mysql
[root@bd005 ~]# wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
--2018-11-08 18:43:55-- http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
Resolving dev.mysql.com (dev.mysql.com)... 137.254.60.11
Connecting to dev.mysql.com (dev.mysql.com)|137.254.60.11|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm [following]
--2018-11-08 18:43:56-- https://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
Connecting to dev.mysql.com (dev.mysql.com)|137.254.60.11|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://repo.mysql.com//mysql57-community-release-el7-8.noarch.rpm [following]
--2018-11-08 18:43:57-- https://repo.mysql.com//mysql57-community-release-el7-8.noarch.rpm
Resolving repo.mysql.com (repo.mysql.com)... 23.50.35.125
Connecting to repo.mysql.com (repo.mysql.com)|23.50.35.125|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9116 (8.9K) [application/x-redhat-package-manager]
Saving to: ‘mysql57-community-release-el7-8.noarch.rpm’ 100%[====================================================================================================================================================================================================================================>] 9,116 --.-K/s in 0s 2018-11-08 18:43:57 (130 MB/s) - ‘mysql57-community-release-el7-8.noarch.rpm’ saved [9116/9116] [root@bd005 ~]# ll
total 20
-rw-------. 1 root root 1276 Aug 18 2017 anaconda-ks.cfg
-rw-r--r--. 1 root root 837 Dec 7 2017 initialize_server.sh
-rw-r--r-- 1 root root 9116 Apr 11 2016 mysql57-community-release-el7-8.noarch.rpm
[root@bd005 ~]# mv mysql57-community-release-el7-8.noarch.rpm /usr/local/softs/
[root@bd005 ~]# cd /usr/local/softs/
[root@bd005 softs]# ll
total 9416
-rw-r--r-- 1 root root 9625824 Nov 6 17:37 apache-tomcat-8.5.34.tar.gz
-rw-r--r-- 1 root root 9116 Apr 11 2016 mysql57-community-release-el7-8.noarch.rpm
drwxr-xr-x 9 root root 220 Nov 8 17:34 tomcat8534
[root@bd005 softs]# mkdir rpms
[root@bd005 softs]# mv mysql57-community-release-el7-8.noarch.rpm rpms/
[root@bd005 softs]# ll
total 9404
-rw-r--r-- 1 root root 9625824 Nov 6 17:37 apache-tomcat-8.5.34.tar.gz
drwxr-xr-x 2 root root 56 Nov 8 18:44 rpms
drwxr-xr-x 9 root root 220 Nov 8 17:34 tomcat8534
[root@bd005 softs]# yum localinstall rpms/mysql57-community-release-el7-8.noarch.rpm
Loaded plugins: fastestmirror
Examining rpms/mysql57-community-release-el7-8.noarch.rpm: mysql57-community-release-el7-8.noarch
Marking rpms/mysql57-community-release-el7-8.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package mysql57-community-release.noarch 0:el7-8 will be installed
--> Finished Dependency Resolution Dependencies Resolved ==============================================================================================================================================================================================================================================================================
Package Arch Version Repository Size
==============================================================================================================================================================================================================================================================================
Installing:
mysql57-community-release noarch el7-8 /mysql57-community-release-el7-8.noarch 8.2 k Transaction Summary
==============================================================================================================================================================================================================================================================================
Install 1 Package Total size: 8.2 k
Installed size: 8.2 k
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : mysql57-community-release-el7-8.noarch 1/1
Verifying : mysql57-community-release-el7-8.noarch 1/1 Installed:
mysql57-community-release.noarch 0:el7-8 Complete!
[root@bd005 softs]# yum install mysql-community-server
Loaded plugins: fastestmirror
mysql-connectors-community | 2.5 kB 00:00:00
mysql-tools-community | 2.5 kB 00:00:00
mysql57-community | 2.5 kB 00:00:00
(1/3): mysql-connectors-community/x86_64/primary_db | 29 kB 00:00:00
(2/3): mysql-tools-community/x86_64/primary_db | 48 kB 00:00:00
(3/3): mysql57-community/x86_64/primary_db | 162 kB 00:00:01
Loading mirror speeds from cached hostfile
* base: mirrors.huaweicloud.com
* extras: mirrors.huaweicloud.com
* updates: mirrors.huaweicloud.com
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.7.24-1.el7 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 5.7.24-1.el7 for package: mysql-community-server-5.7.24-1.el7.x86_64
--> Processing Dependency: mysql-community-client(x86-64) >= 5.7.9 for package: mysql-community-server-5.7.24-1.el7.x86_64
--> Processing Dependency: net-tools for package: mysql-community-server-5.7.24-1.el7.x86_64
--> Running transaction check
---> Package mysql-community-client.x86_64 0:5.7.24-1.el7 will be installed
--> Processing Dependency: mysql-community-libs(x86-64) >= 5.7.9 for package: mysql-community-client-5.7.24-1.el7.x86_64
---> Package mysql-community-common.x86_64 0:5.7.24-1.el7 will be installed
---> Package net-tools.x86_64 0:2.0-0.22.20131004git.el7 will be installed
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.56-2.el7 will be obsoleted
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64
---> Package mysql-community-libs.x86_64 0:5.7.24-1.el7 will be obsoleting
--> Running transaction check
---> Package mysql-community-libs-compat.x86_64 0:5.7.24-1.el7 will be obsoleting
--> Finished Dependency Resolution Dependencies Resolved ==============================================================================================================================================================================================================================================================================
Package Arch Version Repository Size
==============================================================================================================================================================================================================================================================================
Installing:
mysql-community-libs x86_64 5.7.24-1.el7 mysql57-community 2.2 M
replacing mariadb-libs.x86_64 1:5.5.56-2.el7
mysql-community-libs-compat x86_64 5.7.24-1.el7 mysql57-community 2.0 M
replacing mariadb-libs.x86_64 1:5.5.56-2.el7
mysql-community-server x86_64 5.7.24-1.el7 mysql57-community 165 M
Installing for dependencies:
mysql-community-client x86_64 5.7.24-1.el7 mysql57-community 24 M
mysql-community-common x86_64 5.7.24-1.el7 mysql57-community 274 k
net-tools x86_64 2.0-0.22.20131004git.el7 base 305 k Transaction Summary
==============================================================================================================================================================================================================================================================================
Install 3 Packages (+3 Dependent packages) Total download size: 194 M
Is this ok [y/d/N]: y
Downloading packages:
warning: /var/cache/yum/x86_64/7/mysql57-community/packages/mysql-community-common-5.7.24-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY ] 362 kB/s | 280 kB 00:09:08 ETA
Public key for mysql-community-common-5.7.24-1.el7.x86_64.rpm is not installed
(1/6): mysql-community-common-5.7.24-1.el7.x86_64.rpm | 274 kB 00:00:01
(2/6): mysql-community-libs-5.7.24-1.el7.x86_64.rpm | 2.2 MB 00:00:02
(3/6): mysql-community-libs-compat-5.7.24-1.el7.x86_64.rpm | 2.0 MB 00:00:02
(4/6): net-tools-2.0-0.22.20131004git.el7.x86_64.rpm | 305 kB 00:00:01
(5/6): mysql-community-server-5.7.24-1.el7.x86_64.rpm | 165 MB 00:01:57
(6/6): mysql-community-client-5.7.24-1.el7.x86_64.rpm | 24 MB 00:04:28
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 739 kB/s | 194 MB 00:04:28
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Importing GPG key 0x5072E1F5:
Userid : "MySQL Release Engineering <mysql-build@oss.oracle.com>"
Fingerprint: a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5
Package : mysql57-community-release-el7-8.noarch (installed)
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : mysql-community-common-5.7.24-1.el7.x86_64 1/7
Installing : mysql-community-libs-5.7.24-1.el7.x86_64 2/7
Installing : mysql-community-client-5.7.24-1.el7.x86_64 3/7
Installing : net-tools-2.0-0.22.20131004git.el7.x86_64 4/7
Installing : mysql-community-server-5.7.24-1.el7.x86_64 5/7
Installing : mysql-community-libs-compat-5.7.24-1.el7.x86_64 6/7
Erasing : 1:mariadb-libs-5.5.56-2.el7.x86_64 7/7
Verifying : net-tools-2.0-0.22.20131004git.el7.x86_64 1/7
Verifying : mysql-community-libs-compat-5.7.24-1.el7.x86_64 2/7
Verifying : mysql-community-libs-5.7.24-1.el7.x86_64 3/7
Verifying : mysql-community-client-5.7.24-1.el7.x86_64 4/7
Verifying : mysql-community-server-5.7.24-1.el7.x86_64 5/7
Verifying : mysql-community-common-5.7.24-1.el7.x86_64 6/7
Verifying : 1:mariadb-libs-5.5.56-2.el7.x86_64 7/7 Installed:
mysql-community-libs.x86_64 0:5.7.24-1.el7 mysql-community-libs-compat.x86_64 0:5.7.24-1.el7 mysql-community-server.x86_64 0:5.7.24-1.el7 Dependency Installed:
mysql-community-client.x86_64 0:5.7.24-1.el7 mysql-community-common.x86_64 0:5.7.24-1.el7 net-tools.x86_64 0:2.0-0.22.20131004git.el7 Replaced:
mariadb-libs.x86_64 1:5.5.56-2.el7 Complete!
[root@bd005 softs]# systemctl start mysqld
[root@bd005 softs]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Thu 2018-11-08 18:58:01 CST; 6s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 1276 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 1203 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 1280 (mysqld)
CGroup: /system.slice/mysqld.service
└─1280 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid Nov 08 18:57:57 bd005 systemd[1]: Starting MySQL Server...
Nov 08 18:58:01 bd005 systemd[1]: Started MySQL Server.
[root@bd005 softs]# grep 'temporary password' /var/log/mysqld.log //生成临时密码
2018-11-08T10:57:58.087434Z 1 [Note] A temporary password is generated for root@localhost: /GUeg#cGo3MU
[root@bd005 softs]# mysql -uroot -p/GUeg#cGo3MU
[root@bd005 softs]#
mysql>
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '/GUeg#cGo3MU';
Query OK, 0 rows affected (0.00 sec)
mysql> set password for 'root'@'localhost'=password('/GUeg#cGo3MU');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> grant all on *.* to 'root'@'%' identified by '/GUeg#cGo3MU';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> quit;
Bye
[root@bd005 softs]# mysql -uroot -p/GUeg#cGo3MU
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
rows in set (0.00 sec)
## 设置简单的密码
查看当前密码策略
mysql> SHOW VARIABLES LIKE 'validate_password%';
修改mysql配置参数
mysql> set global validate_password_policy=0;
mysql> set global validate_password_mixed_case_count=0;
mysql> set global validate_password_number_count=3;
mysql> set global validate_password_special_char_count=0;
mysql> set global validate_password_length=3;
验证修改后的密码策略
mysql> SHOW VARIABLES LIKE 'validate_password%'; 修改简单密码
mysql> use mysql
mysql> SET PASSWORD = PASSWORD('123456');
mysql> flush privileges; 重启mysql
[root@bd005 softs]# systemctl mysqld restart
## 远程登录设置
授权允许root从任何地址登录设置
mysql> set global validate_password_policy=0;
mysql> set global validate_password_mixed_case_count=0;
mysql> set global validate_password_number_count=3;
mysql> set global validate_password_special_char_count=0;
mysql> set global validate_password_length=3;
mysql> SHOW VARIABLES LIKE 'validate_password%';
授权允许root从任何地址登录
mysql> grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
mysql> flush privileges;
MySQL的一些函数使用小例子:
1、使用随机数函数 RAND
生成0-100的随机整数:SELECT FLOOR((RAND() * 100))
把用户id为0的错误数据使用随机函数改成随机整数ID:UPDATE tbl_logs SET global_user_id=FLOOR(2 + (RAND() * 100)) WHERE global_user_id=0;
2、使用替换函数 REPLACE
将My@SQ@L中的@替换为空字符串:SELECT REPLACE('My@SQ@L', '@', '')
把cookie_text字段中的My@SQ@L修改为MySQL:UPDATE tbl_logs SET cookie_text = REPLACE('My@SQ@L', '@', '') WHERE user_id=0;
3、使用拼接函数 CONCAT和CONCAT_WS
CONCAT函数:
合并3个字符串为一个字符串:SELECT CONCAT('My','S','QL');
CONCAT_WS函数(CONCAT With Separator,带有分隔符的CONCAT函数):
将name,gender,age拼接为name_gender_age:SELECT CONCAT_WS('_',name,gender,age);
4、大小写转换LOWER和UPPER
小写转换-将MySQL转换为mysql:SELECT LOWER('MySQL')
大写转换-将mysql转换为MYSQL:SELECT UPPER('mysql')
5、获取字符串左右指定长度的字符
获取右边4个字符串(YHQ20190720V900N0013中的0013):SELECT RIGHT('YHQ20190720V900N0013',4)
获取左边3个字符串(YHQ20190720V900N0013中的YHQ):SELECT LEFT('YHQ20190720V900N0013',3)
6、去除字符串首尾空格
将' BMW '修改为'BMW':SELECT TRIM(' BMW ')
7、时间和时间戳相互转换
将Date类型的当前时间换换位时间戳:SELECT UNIX_TIMESTAMP(NOW())
将时间戳转换为Date类型:SELECT FROM_UNIXTIME('1565962224')
生成随机指定时间范围内(近1个月)的时间:
SELECT ADDDATE(MAKEDATE(2019, FLOOR(200 + RAND() * 30)), -- 1-30号
INTERVAL MAKETIME(
FLOOR(RAND()*24), -- 0-23点
FLOOR(RAND()*60), -- 0-59分
FLOOR(RAND()*60) -- 0-59秒
) HOUR_SECOND) AS rand_dt;
8、MySQL表的自增ID批量修改
将已有数据的ID修改为从1开始自增:
将表的自增ID设置从1开始:ALTER TABLE tbl_users AUTO_INCREMENT=1
修改表数据的ID:UPDATE tbl_users t SET t.id = (SELECT @n := @n + 1 FROM (SELECT @n := 0) r)
9、MySQL表的时间字段修改为近一个月内的时间
UPDATE tbl_logs_201608 SET log_time = ADDDATE(MAKEDATE(2016, FLOOR(200 + RAND() * 30)), INTERVAL MAKETIME(FLOOR(RAND()*24),FLOOR(RAND()*60),FLOOR(RAND()*60)) HOUR_SECOND)
10、MySQL的case when field=value then value1 else value2 end
SELECT
CASE FLOOR(1+RAND()*20)
WHEN 1 THEN '银色'
WHEN 2 THEN '香槟金色'
WHEN 3 THEN '黑色'
WHEN 4 THEN '白色'
WHEN 5 THEN '梦境极光【卡其金】'
WHEN 6 THEN '梦境极光【布朗灰】'
WHEN 7 THEN '粉色'
WHEN 8 THEN '金属灰'
WHEN 9 THEN '金色'
WHEN 10 THEN '乐享金'
WHEN 11 THEN '布鲁钢'
WHEN 12 THEN '月光银'
WHEN 13 THEN '时尚光谱【浅金棕】'
WHEN 14 THEN '香槟色'
WHEN 15 THEN '香槟金'
WHEN 16 THEN '灰色'
WHEN 17 THEN '樱花粉'
WHEN 18 THEN '蓝色'
WHEN 19 THEN '金属银'
WHEN 20 THEN '玫瑰金'
ELSE '其他' END
AS color
CentOS7安装MySQL5.7以及修改密码的更多相关文章
- Centos7安装Mysql5.7并修改初始密码
1.CentOS 的yum源中没有mysql,需要到mysql的官网下载yum repo配置文件. wget https://dev.mysql.com/get/mysql57-community-r ...
- 安装Mysql5.7并修改初始密码
Centos 安装MySQL可以参考之前写的一篇文章 Centos7.3 安装Mysql5.7并修改初始密码 windows安装mysql5.7有两种方式 1.下载.msi安装文件直接根据界面提示进行 ...
- Centos7 安装 MySQL5.7
Centos7 安装 MySQL5.7 一.环境介绍 1.安装包版本介绍 MySQL 有三种安装方式:RPM安装.二进制包安装.源码包安装.我们这篇文章以二进制方式安装MySQL 软件名称 版本 系统 ...
- centos7安装mysql5.7.19及配置远程连接
centos7安装mysql5.7.19及配置远程连接------https://blog.csdn.net/Lh19931122/article/details/77996213
- centos7安装mysql5.7修改设置密码策略
centos7操作系统在安装mysql5.7社区版之后会有默认密码,通过grep命令在mysqld.log文件中即可找到,如下所示: 标识位置即在初始化安装时mysql的默认密码,然后通过mysql ...
- Linux安装和配置MySQL5.7【修改密码、修改字符集等配置】(5.7.18+版本也可参考,我是5.7.22)
本文是转载篇,这里是 原文原文原文. --------------------分割线------------------------------- 这下面内容讲述如何修改密码为简单密码(比如:1234 ...
- centos7 安装mysql5.7.11注意事项
centos7通过yum install mysql默认安装的是mariadb.至于为什么默认安装mariadb以及mariadb和mysql的区别,网上有很多说明.这里不再阐述,下面介绍下怎么另行下 ...
- Linux学习第三步(Centos7安装mysql5.7数据库)
版本:mysql-5.7.16-1.el7.x86_64.rpm-bundle.tar 前言:在linux下安装mysql不如windows下面那么简单,但是也不是很难.本文向大家讲解了如何在Cent ...
- Centos7安装mysql-5.7.19
Centos7安装Mysql 一 mysql下载 地址: https://dev.mysql.com/downloads/mysql/#downloads 二 在centos7上创建安装文件存放.解压 ...
随机推荐
- 异常--throw
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- 关于houghlines函数角度问题的说明
以上是opecv reference里面的说明. Image必须是8位单通道图(可以使灰度图.二值图.边缘图等) Rho:距离分辨率,一般为1 Theta:角度分辨率,一般为CV_PI/180 Thr ...
- 总结 java 学习
想着想把以前学的java学习笔记整理下发上来,慢慢整理吧.
- [socket编程] 一个服务器与多个客户端之间通信
转自:http://blog.csdn.net/neicole/article/details/7539444 并加以改进 Server程序: // OneServerMain.cpp #includ ...
- BZOJ1037 [ZJOI2008]生日聚会Party 【DP】
1037: [ZJOI2008]生日聚会Party Time Limit: 10 Sec Memory Limit: 162 MB Submit: 2800 Solved: 1654 [Submi ...
- React的this.props.children
this.props用来获取组件从外部传入的属性,但是this.props.children比较特殊,它是由React给添加上的,表示组件的所有子节点.this.props.children可以用来读 ...
- snmp实用篇
简单网络管理协议(SNMP)是 TCP/IP协议簇的一个应用层协议.在1988年被制定,并被Internet体系结构委员会(IAB)采纳作为一个短期的网络管理解决方案:由于 SNMP的简单性,在Int ...
- hdu 5620
KK's Steel Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- Ultra-QuickSort POJ - 2299 树状数组求逆序对
In this problem, you have to analyze a particular sorting algorithm. The algorithm processes a seque ...
- Getting Private/Public IP address of EC2 instance using AWS-cli [closed]
For private IP address: aws ec2 describe-instances --instance-ids i-b78a096f | grep PrivateIpAddress ...