MySQL5.7初始配置
MySQL5.7初始配置
Windows7 环境安装MySQL5.7配置命令
《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《《
MYSQL_HOME D:\mysql\mysql-5.7.20-win32
MYSQL_CONNECTOR_HOME D:\mysql\mysql-connector-c-6.1.11-win32\bin
PATH ;%MYSQL_HOME%\bin;%MYSQL_CONNECTOR_HOME%\bin
####################配置文件开始###################
# 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]
character-set-server = utf8
bind-address = 0.0.0.0
port = 3306
basedir = "D:\mysql\mysql-5.7.20-win32/"
datadir = "D:\mysql\mysql-5.7.20-win32/data/"
tmpdir = "D:\mysql\mysql-5.7.20-win32/data/"
socket = "D:\mysql\mysql-5.7.20-win32/data/mysql.sock"
log-error = "D:\mysql\mysql-5.7.20-win32/data/mysql_error.log"
#server_id = 2
#skip-locking
max_connections = 100
table_open_cache = 256
query_cache_size = 1M
tmp_table_size = 32M
thread_cache_size = 8
innodb_data_home_dir = "D:\mysql\mysql-5.7.20-win32/data/"
innodb_flush_log_at_trx_commit = 1
innodb_log_buffer_size = 128M
innodb_buffer_pool_size = 128M
innodb_log_file_size = 10M
innodb_thread_concurrency = 16
innodb-autoextend-increment = 1000
join_buffer_size = 128M
sort_buffer_size = 32M
read_rnd_buffer_size = 32M
max_allowed_packet = 32M
explicit_defaults_for_timestamp = true
sql-mode = "STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
#skip-grant-tables
#sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[mysql]
default-character-set=utf8
[mysql.server]
default-character-set=utf8
[mysql_safe]
default-character-set=utf8
[client]
####################配置文件结束###################
mysqld remove
mysqld --install MySQL --defaults-file="D:\mysql\mysql-5.7.20-win32\my.ini"
mysqld --initialize
net start MySQL
net stop mysql
初始的随机密码可以在日志文件中找到(log-error = "D:\mysql\mysql-5.7.20-win32/data/mysql_error.log")
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
安装完mysql 之后,登陆以后,不管运行任何命令,总是提示这个
step 1: SET PASSWORD = PASSWORD('your new password');
step 2: ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
step 3: flush privileges;
完成以上三步退出再登,使用新设置的密码就行了,以上除了红色的自己修改成新密码外,其他原样输入即可
参考1: https://dev.mysql.com/doc/refman/5.6/en/alter-user.html
参考2: http://dev.mysql.com/doc/refman/5.7/en/password-expiration-policy.html
参考3: http://stackoverflow.com/questions/33467337/reset-mysql-root-password-using-alter-user-statement-after-install-on-mac
select user,host,authentication_string,password_expired from mysql.user;
update mysql.user set authentication_string=password('qwe123') where user='root' and host='localhost';
alter user 'root'@'localhost' identified by 'qwe123';
FLUSH PRIVILEGES;
》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》
MariaDB 安装配置
下载地址 http://downloads.mariadb.com/MariaDB/mariadb-10.2.11/winx64-packages/
# Example MariaDB config file for large systems.
#
# This is for a large system with memory = 512M where the system runs mainly
# MariaDB.
#
# MariaDB programs look for option files in a set of
# locations which depend on the deployment platform.
# You can copy this option file to one of those
# locations. For information about these locations, do:
# 'my_print_defaults --help' and see what is printed under
# Default options are read from the following files in the given order:
# More information at: http://dev.mysql.com/doc/mysql/en/option-files.html
#
# In this file, you can use all long options that a program supports.
# If you want to know which options a program supports, run the program
# with the "--help" option. # The following options will be passed to all MariaDB clients ############################### # Installation steps:
# 1: mysqld --install MariaDB --defaults-file="D:\mariadb-10.2.11-winx64\my.ini"
# 2: MySQL: mysqld --initialize
# MariaDB: mysql_install_db.exe --datadir="D:\mariadb-10.2.11-winx64\mydb"
# 3: net start MariaDB
# 4: net stop MariaDB # Update localhost root password:
# 1: select user,host,authentication_string,password_expired from mysql.user;
# 2: update mysql.user set authentication_string=password('qwe123') where user='root' and host='localhost';
# 3: alter user 'root'@'localhost' identified by 'qwe123';
# 4: FLUSH PRIVILEGES; # Change the password to qwe123
# 1: mysqladmin -u root -p password qwe123 # Setting up root remote access
# 1: mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'qwe123' WITH GRANT OPTION;
# 2: mysql> FLUSH PRIVILEGES; # Create new database and user
# 1: create database weblm character set utf8;
# 2: grant all privileges on weblm.* to 'weblm'@'localhost' identified by 'weblm';
# 3: flush privileges; ############################### [client]
#password = your_password
port = 3306
socket = "D:\mariadb-10.2.11-winx64/mydb/mysql.sock" default-character-set = utf8 # Here follows entries for some specific programs # The MariaDB server
[mysqld]
port = 3306 basedir = "D:\mariadb-10.2.11-winx64"
datadir = "D:\mariadb-10.2.11-winx64/mydb/"
tmpdir = "D:\mariadb-10.2.11-winx64/mydb/"
socket = "D:\mariadb-10.2.11-winx64/mydb/mysql.sock"
log-error = "D:\mariadb-10.2.11-winx64/mydb/mysql_error.log" init_connect = 'SET collation_connection = utf8_unicode_ci'
init_connect = 'SET NAMES utf8'
character-set-server = utf8
collation-server = utf8_unicode_ci
skip-character-set-client-handshake skip-external-locking
key_buffer_size = 256M
max_allowed_packet = 1M
table_open_cache = 256
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 4M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size = 16M # Try number of CPU's*2 for thread_concurrency
#thread_concurrency = 8 # Point the following paths to different dedicated disks
#tmpdir = /tmp/ # Don't listen on a TCP/IP port at all. This can be a security enhancement,
# if all processes that need to connect to mysqld run on the same host.
# All interaction with mysqld must be made via Unix sockets or named pipes.
# Note that using this option without enabling named pipes on Windows
# (via the "enable-named-pipe" option) will render mysqld useless!
#
#skip-networking # Replication Master Server (default)
# binary logging is required for replication
log-bin = mysql-bin # binary logging format - mixed recommended
binlog_format = mixed # required unique id between 1 and 2^32 - 1
# defaults to 1 if master-host is not set
# but will not function as a master if omitted
server-id = 1 # Replication Slave (comment out master section to use this)
#
# To configure this host as a replication slave, you can choose between
# two methods :
#
# 1) Use the CHANGE MASTER TO command (fully described in our manual) -
# the syntax is:
#
# CHANGE MASTER TO MASTER_HOST=<host>, MASTER_PORT=<port>,
# MASTER_USER=<user>, MASTER_PASSWORD=<password> ;
#
# where you replace <host>, <user>, <password> by quoted strings and
# <port> by the master's port number (3306 by default).
#
# Example:
#
# CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306,
# MASTER_USER='joe', MASTER_PASSWORD='secret';
#
# OR
#
# 2) Set the variables below. However, in case you choose this method, then
# start replication for the first time (even unsuccessfully, for example
# if you mistyped the password in master-password and the slave fails to
# connect), the slave will create a master.info file, and any later
# change in this file to the variables' values below will be ignored and
# overridden by the content of the master.info file, unless you shutdown
# the slave server, delete master.info and restart the slaver server.
# For that reason, you may want to leave the lines below untouched
# (commented) and instead use CHANGE MASTER TO (see above)
#
# required unique id between 2 and 2^32 - 1
# (and different from the master)
# defaults to 2 if master-host is set
# but will not function as a slave if omitted
#server-id = 2
#
# The replication master for this slave - required
#master-host = <hostname>
#
# The username the slave will use for authentication when connecting
# to the master - required
#master-user = <username>
#
# The password the slave will authenticate with when connecting to
# the master - required
#master-password = <password>
#
# The port the master is listening on.
# optional - defaults to 3306
#master-port = <port>
#
# binary logging - not required for slaves, but recommended
#log-bin=mysql-bin # Uncomment the following if you are using InnoDB tables
#innodb_data_home_dir = C:\\mysql\\data\\
#innodb_data_file_path = ibdata1:10M:autoextend
#innodb_log_group_home_dir = C:\\mysql\\data\\
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
#innodb_buffer_pool_size = 256M
#innodb_additional_mem_pool_size = 20M
# Set .._log_file_size to 25 % of buffer pool size
#innodb_log_file_size = 64M
#innodb_log_buffer_size = 8M
#innodb_flush_log_at_trx_commit = 1
#innodb_lock_wait_timeout = 50 [mysqldump]
quick
max_allowed_packet = 16M [mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates default-character-set = utf8 [myisamchk]
key_buffer_size = 128M
sort_buffer_size = 128M
read_buffer = 2M
write_buffer = 2M [mysqlhotcopy]
interactive-timeout ###############################
安装后在/root目录下没有发现有.mysql_secret这个文件,所以没有没法按照官方文档上说的那样使用,这里记录下,
解决方式:
首先修改MySQL授权登录方式---(跳过授权验证方式启动MySQL):
[root@test ~]# mysqld_safe --skip-grant-tables &
[1] 3401
[root@test ~]# 2016-05-19T12:47:56.564385Z mysqld_safe Logging to '/var/log/mysqld.log'.
2016-05-19T12:47:56.589376Z mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
检查MySQL启动情况
[root@test ~]# ps -ef | grep mysql
root 3401 2880 0 20:47 pts/1 00:00:00 /bin/sh /usr/bin/mysqld_safe --skip-grant-tables
mysql 3548 3401 0 20:47 pts/1 00:00:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --skip-grant-tables --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock
这时登录MySQL不再需要验证
[root@test ~]# mysql
成功登录MySQL后:
切换到mysql系统库:
mysql> use mysql; 修改root账户登录密码:
mysql> update user set password=password('') where user='root';
ERROR 1054 (42S22): Unknown column 'password' in 'field list'
---报错没有password这个数据字段列
描述user表
mysql> desc user;
...
| authentication_string | text | YES | | NULL | |
| password_expired | enum('N','Y') | NO | | N | |
| password_last_changed | timestamp | YES | | NULL | |
| password_lifetime | smallint(5) unsigned | YES | | NULL | |
| account_locked | enum('N','Y') | NO | | N | |
+------------------------+-----------------------------------+------+-----+-----------------------+-------+
---没发现password列,但是找到这5个跟密码相关的数据字段
查询一下相关的密码信息:
mysql> select user,host,authentication_string,password_expired from user;
+-----------+-----------+-------------------------------------------+------------------+
| user | host | authentication_string | password_expired |
+-----------+-----------+-------------------------------------------+------------------+
| root | localhost | *9AA01F6E2A80A823ACB72CC07337E2911404B5B8 | Y |
| mysql.sys | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | N |
+-----------+-----------+-------------------------------------------+------------------+
---到这里不难发现root账户的密码已过期,还比5.6多出了一个mysql.sys用户
修改密码
mysql> update user set authentication_string=password('123abc') 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
密码修改成功,测试:
重启MySQL:
[root@test ~]# /etc/init.d/mysqld restart 登录测试:
[root@test ~]# mysql -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.12-enterprise-commercial-advanced
...
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
---报错,需要使用alter user 修改密码
mysql> alter user root@'localhost' identified by 'oracle';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
---报错,密码不满足制定的密码负责度要求
mysql> alter user 'root'@'localhost' identified by 'Abc!123D';
Query OK, 0 rows affected (0.01 sec) mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
关于密码策略
mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+--------+
| Variable_name | Value |
+--------------------------------------+--------+
| validate_password_dictionary_file | |
| validate_password_length | 8 |
| validate_password_mixed_case_count | 1 |
| validate_password_number_count | 1 |
| validate_password_policy | MEDIUM |
| validate_password_special_char_count | 1 |
+--------------------------------------+--------+
6 rows in set (0.02 sec) mysql> show plugins;
+----------------------------+----------+--------------------+----------------------+-------------+
| Name | Status | Type | Library | License |
+----------------------------+----------+--------------------+----------------------+-------------+
| binlog | ACTIVE | STORAGE ENGINE | NULL | PROPRIETARY | ...
| validate_password | ACTIVE | VALIDATE PASSWORD | validate_password.so | PROPRIETARY |
+----------------------------+----------+--------------------+----------------------+-------------+
---可以通过在配置文件[mysqld]标签中添加 validate_passwor=off ,来关闭密码策略
如下:
...
| validate_password | DISABLED | VALIDATE PASSWORD | validate_password.so | PROPRIETARY |
+----------------------------+----------+--------------------+----------------------+-------------+
总结
1) 安装好mysql后,第一次启动时,root管理密码会在/root/.mysql_secret中随机生成
2) 至5.7后,MySQL的 mysql.user 表中的密码字段由之前的 password 改为 authentication_string
3) 使用--skip-grant-tables 参数启动,跳过MySQL的授权验证,--skip-networking参数,跳过远程登录
4) 修改MySQL密码方式:
法1:update user set authentication_string=password('123abc') where user='root';
法2:set password=password('newpassword');
法3:alter user root@'localhost' identified by 'oracle';
法4:在shell下使用MySQL工具:mysqladmin -uroot -poldpassword pasword "newpassword"
5) 关于MySQL密码策略:
后记
经过一段时间后,发现mysql初始密码原来被记录到了日志文件中
查找日志位置
[root@test /var/lib/mysql]# ps -ef | grep mysql
root 5604 1 0 22:40 pts/1 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 5802 5604 5 22:40 pts/1 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 5837 2880 0 22:40 pts/1 00:00:00 grep --color mysql
藏在日志文件中的临时密码
[root@test /var/lib/mysql]# grep "A temporary password" /var/log/mysqld.log
2016-05-17T16:46:53.059632Z 1 [Note] A temporary password is generated for root@localhost: +wGVA#to(4tu
MySQL5.7初始配置的更多相关文章
- win7 64bit下最新Apahe2.4.18+php7.0.2+MySQL5.7.10配置
原文:win7 64bit下最新Apahe2.4.18+php7.0.2+MySQL5.7.10配置 一.说明 以前配置apache+php+mysql都是参考网上的,一般都没有什么问题.最近公司有个 ...
- Centos6.5 安装MYSQL 5.5 -5.6.-5.7 一键yum快速安装 ,初始配置
Centos6.5 安装MYSQL 5.5 ---5.6---5.7 一键yum快速安装 ,初始配置 第一步:安装mysql-5.5---- 5.6 ---- 5.7的yum源 [root@sv03 ...
- appach2.4 + php7 +mysql5.7.14 配置
步骤1.首先打开Apache2.2\conf里面的httpd.conf文件.在里面找到: ServerRoot ,改成Appache所在目录 步骤二 在LoadModule 后面添加支持php7的扩 ...
- Git 笔记二-Git安装与初始配置
git 笔记二-Git安装与初始配置 Git的安装 由于我日常生活和工作基本上都是在Windows上,因此此处只说windows上的安装.Windows上的安装和其他程序一样,只需要到http://g ...
- win8安装mysql5.5最后配置没有反应
win8安装mysql5.5最后配置没有反应 win8下安装mysql5.5一路顺利,可是到最后一步配置mysql服务及登录password后.注冊服务并启动服务界面一直没有不论什么反应: 本来以为是 ...
- IDEA 初始配置教程
IDEA 初始配置教程 如果你是第一次使用 IDEA,或者对 IDEA 常用配置仍然不熟悉,那么本文就特别适合你. 本文只是根据我自己的使用经验来进行配置,不一定适合所有的情况,但是对你肯定会有帮助. ...
- Git初始配置和基本使用
初次运行Git前的配置 本文是在安裝完git以后首先应做到一些配置,安装教程可以参考廖雪峰git教程 用户信息 当安装完 Git 应该做的第一件事就是设置你的用户名称与邮件地址. 这样做很重要,因为每 ...
- paloalto防火墙执行初始配置
1.默认情况下,防火墙的 IP 地址为 192.168.1.1,用户名/密码为 admin/admin. 为了安全起见,在继续执行其他防火墙配置任务之前,必须更改这些设置.必须从 MGT 接口(即使计 ...
- Testlink1.9.17使用方法( 第三章 初始配置[配置用户、产品] )
第三章 初始配置(配置用户.产品) 一. 设置用户 QQ交流群:585499566 在TestLink系统中,每个用户都可以维护自己的私有信息.admin可以创建用户,但不能看到其它用户的密码.在用户 ...
随机推荐
- nowcoder wannafly 25 E:01串
E:01 串 链接 分析: 线段树维护转移矩阵.每个节点是一个矩阵,区间内的矩阵乘起来就是答案矩阵.矩阵乘法满足结合律,所以线段树维护. 代码: #include<cstdio> #inc ...
- [CF888E] Maximum Subsequence 序列分治
早期作品,不喜轻喷. LG传送门 序列分治板子题. 切这道题用了好长时间,所以想发篇题解作为纪念 . 首先,我们认真观察题目数据(面向数据做题是个好习惯),发现题目的\(n\)竟然只有\(35\),我 ...
- 记录使用jQuery和Python抓取采集数据的一个实例
从现成的网站上抓取汽车品牌,型号,车系的数据库记录. 先看成果,大概4w条车款记录 一共建了四张表,分别存储品牌,车系,车型和车款 大概过程: 使用jQuery获取页面中呈现的大批内容 能通过页面一次 ...
- (转) 理解Angular中的$apply()以及$digest()
原文地址:http://blog.csdn.net/dm_vincent/article/details/38705099 $apply()和$digest()在AngularJS中是两个核心概念,但 ...
- Appium+python 自动发送邮件(1)(转)
(原文:https://www.cnblogs.com/fancy0158/p/10056091.html) SMTP:简单传输协议,实在Internet上传输Email的事实标准. Python的s ...
- cookie,session傻傻分不清楚?
做了这么多年测试,还是分不清什么是cookie,什么是session?很正常,很多初级开发工程师可能到现在都搞不清什么是session,cookie相对来说会简单很多. 下面这篇文章希望能够帮助大家分 ...
- qs.js - 更好的处理url参数
第一次接触 qs 这个库,是在使用axios时,用于给post方法编码,在使用过程中,接触到了一些不同的用法,写在这里分享一下. qs.parse qs.parse 方法可以把一段格式化的字符串转换为 ...
- Red Hat Enterprise Linux / CentOS 7 yum安装zabbix4.0
添加Zabbix存储库安装存储库配置包. 该软件包包含yum(软件包管理器)配置文件. rpm -ivh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_6 ...
- [转]C#学习笔记15——C#多线程编程
一.基本概念进程:当一个程序开始运行时,它就是一个进程,进程包括运行中的程序和程序所使用到的内存和系统资源.而一个进程又是由多个线程所组成的.线程:线程是程序中的一个执行流,每个线程都有自己的专有寄存 ...
- BZOJ 1901 Zju2112 Dynamic Rankings 树状数组套线段树
题意概述:带修改求区间第k大. 分析: 我们知道不带修改的时候直接上主席树就可以了对吧?两个版本号里面的节点一起走在线段树上二分,复杂度是O((N+M)logN). 然而这里可以修改,主席树显然是凉了 ...