<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>http://jackxiang.com/post/8651/</link>
<title><![CDATA[[实践OK]最新mysql，[ERROR] COLLATION utf8_general_ci is not valid for CHARACTER SET latin1,及mysql-5.7.12的初始化密码放error.log了。]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[数据库技术]]></category>
<pubDate>Thu, 21 Apr 2016 03:41:46 +0000</pubDate> 
<guid>http://jackxiang.com/post/8651/</guid> 
<description>
<![CDATA[ 
	背景：最近研究一下rpmbuild打的mysql最新包出现初始化mysql-5.7.12时的数据库错误，[ERROR] COLLATION &#039;utf8_general_ci&#039; is not valid for CHARACTER SET &#039;latin1&#039;，再涉及到mysql的密码问题居然放error.log里了。<br/>1）init database and set password：<br/>[root@localhost bin]#./mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql <br/>2016-04-21T03:26:22.900370Z 0 [ERROR] COLLATION &#039;utf8_general_ci&#039; is not valid for CHARACTER SET &#039;latin1&#039;<br/>2016-04-21T03:26:22.900452Z 0 [ERROR] Aborting<br/>2)try directly start mysql server display:<br/>[root@localhost bin]# ./mysqld_safe&nbsp;&nbsp;<br/>./mysqld_safe: line 541: /data/mysql/mysqld_safe.pid: No such file or directory<br/>awk: (FILENAME=- FNR=1) warning: error writing standard output (Broken pipe)<br/>2016-04-21T03:26:28.773480Z mysqld_safe Logging to &#039;/data/logs/mysql/error.log&#039;.<br/>2016-04-21T03:26:28.814486Z mysqld_safe Starting mysqld daemon with databases from /data/mysql<br/>2016-04-21T03:26:28.957913Z mysqld_safe mysqld from pid file /data/mysql/mysql.pid ended<br/><br/>so,tail -f ,tail -f /data/logs/mysql/error.log<br/><textarea name="code" class="php" rows="15" cols="100">
2016-04-21T03:26:45.171898Z mysqld_safe Starting mysqld daemon with databases from /data/mysql
2016-04-21T03:26:45.303137Z 0 [Warning] Insecure configuration for --secure-file-priv: Current value does not restrict location of generated files. Consider setting it to a valid, non-empty path.
2016-04-21T03:26:45.303235Z 0 [Note] /usr/local/mysql/bin/mysqld (mysqld 5.7.12-log) starting as process 26969 ...
2016-04-21T03:26:45.305219Z 0 [ERROR] COLLATION &#039;utf8_general_ci&#039; is not valid for CHARACTER SET &#039;latin1&#039;
</textarea><br/><br/> 乍一看，是字符编码问题，着实在my.cnf配置文件上面设置了字符编码如下：&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br/><textarea name="code" class="php" rows="15" cols="100">
[client]
default-character-set = utf8
[mysqld]
character_set_server = utf8
</textarea><br/><br/>再启动，出现新的报错：<br/><textarea name="code" class="php" rows="15" cols="100">
2016-04-21T03:34:25.386145Z 0 [ERROR] failed to set datadir to /data/mysql/
2016-04-21T03:34:25.386164Z 0 [ERROR] Aborting
2016-04-21T03:34:25.386182Z 0 [Note] Binlog end
2016-04-21T03:34:25.386370Z 0 [Note] /usr/local/mysql/bin/mysqld: Shutdown complete
</textarea><br/>可能是目录的权限问题，继续在rpmbuild里写上权限....<br/>chmod -R mysql.mysql /data/logs/mysql /data/mysql<br/><br/>[root@localhost bin]# ./mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql&nbsp;&nbsp;<br/>[root@localhost bin]# <br/><br/>日志跟踪，敬告没有Error：<br/>2016-04-21T03:45:21.971611Z 1 [Warning] &#039;user&#039; entry &#039;root@localhost&#039; ignored in --skip-name-resolve mode.<br/>2016-04-21T03:45:21.971676Z 1 [Warning] &#039;user&#039; entry &#039;mysql.sys@localhost&#039; ignored in --skip-name-resolve mode.<br/>2016-04-21T03:45:21.971712Z 1 [Warning] &#039;db&#039; entry &#039;sys mysql.sys@localhost&#039; ignored in --skip-name-resolve mode.<br/>2016-04-21T03:45:21.971745Z 1 [Warning] &#039;proxies_priv&#039; entry &#039;@ root@localhost&#039; ignored in --skip-name-resolve mode.<br/>2016-04-21T03:45:21.972041Z 1 [Warning] &#039;tables_priv&#039; entry &#039;sys_config mysql.sys@localhost&#039; ignored in --skip-name-resolve mode.<br/><br/><br/>立即启动mysqld_safe：<br/>[root@localhost bin]# ./mysqld_safe <br/>2016-04-21T03:47:08.025776Z mysqld_safe Logging to &#039;/data/logs/mysql/error.log&#039;.<br/>2016-04-21T03:47:08.075873Z mysqld_safe Starting mysqld daemon with databases from /data/mysql<br/><br/>tail -f /data/logs/mysql/error.log 端口成功启动：<br/>2016-04-21T03:47:08.542210Z 0 [Note] /usr/local/mysql/bin/mysqld: ready for connections.<br/>Version: &#039;5.7.12-log&#039;&nbsp;&nbsp;socket: &#039;/tmp/mysql.sock&#039;&nbsp;&nbsp;port: 3306&nbsp;&nbsp;Source distribution<br/><br/><br/>[root@localhost bin]# ./mysql -uroot -p<br/>Enter password: <br/>ERROR 1045 (28000): Access denied for user &#039;root&#039;@&#039;localhost&#039; (using password: NO)<br/><br/>重新初始化mysql用户名及密码：<br/>[root@localhost bin]# ./bin/mysql_install_db --basedir=. --datadir=/data/mysql --user=mysql<br/>2016-04-21 13:18:24 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize<br/>2016-04-21 13:18:24 [ERROR]&nbsp;&nbsp; The data directory needs to be specified.<br/>之前版本mysql_install_db是在mysql_basedir/script下，5.7放在了mysql_install_db/bin目录下,且已被废弃。<br/><br/>shell&gt;./mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql <br/>******mysql5.7会生成一个初始化密码，而在之前的版本首次登陆不需要登录。(我前面用的是root启动的)：<br/>[root@localhost bin]# ./mysqld_safe --user=mysql&nbsp;&nbsp;&nbsp;&nbsp; <br/>2016-04-21T05:24:34.317097Z mysqld_safe Logging to &#039;/data/logs/mysql/error.log&#039;.<br/>2016-04-21T05:24:34.463814Z mysqld_safe Starting mysqld daemon with databases from /data/mysql<br/><textarea name="code" class="php" rows="15" cols="100">
shell&gt; cat /root/.mysql_secret 
# Password set for user &#039;root@localhost&#039; at 2015-04-22 22:13:23 
?G5W&amp;tz1z.cN

修改默认密码
shell&gt; bin/mysqladmin -h localhost -u root password &#039;123@qwe&#039; -p&#039;?G5W&amp;tz1z.cN&#039;
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
另外mysql5.7的mysql.user表结构被修改

修改mysql.user方式修改密码
mysql&gt; update mysql.user set authentication_string=password(&#039;123qwe&#039;) where user=&#039;svoid&#039; and Host = &#039;localhost&#039;;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1&nbsp;&nbsp;Changed: 1&nbsp;&nbsp;Warnings: 0

mysql&gt; flush privileges;
Query OK, 0 rows affected (0.00 sec)
整理自网络
</textarea><br/>这帮孙子现在是在抽风么，网上查到这密码放哪儿是一个折腾呐，那最新版本的放哪儿了？<br/>MySQL 5.6 中，mysql_install_db 在数据库创建的时候提供选项来生成 random password。<br/>MySQL 5.7.4 中，可以跳过 -skip-random-password 选项来默认生成随机密码。<br/>MySQL 5.7.5 中，还是默认生成随机密码，但是选项修改为 –insecure<br/><br/>摸索下看：<br/><textarea name="code" class="php" rows="15" cols="100">
[root@localhost bin]# ./mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql&nbsp;&nbsp;--skip-random-password&nbsp;&nbsp; //不认--skip-random-password, unknown option &#039;--skip-random-password&#039;.&nbsp;&nbsp; 
2016-04-21T05:30:11.223901Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
[root@localhost bin]# rm -Rf /data/mysql/*
[root@localhost bin]# ./mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql 
</textarea><br/><br/>tail日志时发现，mysql-5.7.12最新版本的密码放在error.log里面了，我去：<br/><textarea name="code" class="php" rows="15" cols="100">
[root@localhost bin]# tail -f /data/logs/mysql/error.log

......
2016-04-21T05:33:28.538633Z 1 [Note] A temporary password is generated for root@localhost: 7EEgNltAA1;/
......
</textarea><br/><br/>[root@localhost bin]# ./mysqld_safe --user=mysql &amp;<br/>[1] 18730<br/><br/>2016-04-21T05:36:56.824891Z 0 [Note] /usr/local/mysql/bin/mysqld: ready for connections.<br/>Version: &#039;5.7.12-log&#039;&nbsp;&nbsp;socket: &#039;/tmp/mysql.sock&#039;&nbsp;&nbsp;port: 3306&nbsp;&nbsp;Source distribution<br/><br/>连接成功,这个新版本的msyql还真TM费劲呐：<br/>[root@localhost ~]# mysql -uroot -p<br/>Enter password: 7EEgNltAA1;/<br/>Welcome to the MySQL monitor.&nbsp;&nbsp;Commands end with ; or &#92;g.<br/>Your MySQL connection id is 2<br/>Server version: 5.7.12-log<br/><br/>Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.<br/><br/>Oracle is a registered trademark of Oracle Corporation and/or its<br/>affiliates. Other names may be trademarks of their respective<br/>owners.<br/><br/>Type &#039;help;&#039; or &#039;&#92;h&#039; for help. Type &#039;&#92;c&#039; to clear the current input statement.<br/><br/>mysql&gt; <br/><br/>强制要求你修改密码：<br/>mysql&gt; show databases;<br/>ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.<br/>mysql&gt; SET PASSWORD = PASSWORD(&#039;123456&#039;);<br/>Query OK, 0 rows affected, 1 warning (0.00 sec)<br/>mysql&gt; create database jackTestDB;<br/>Query OK, 1 row affected (0.00 sec)<br/><br/><br/>不要密码初始化数据库的参数，参考自：https://dev.mysql.com/doc/refman/5.7/en/data-directory-initialization-mysqld.html<br/><textarea name="code" class="php" rows="15" cols="100">
rm -Rf /data/mysql&nbsp;&nbsp;//原来生成的给去掉
[root@localhost bin]# ./mysqld --initialize-insecure&nbsp;&nbsp;--user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
[root@localhost bin]#&nbsp;&nbsp;./mysqld_safe --user=mysql &amp;
</textarea><br/>[1] 59478<br/>无密码连接一下看：<br/>[root@localhost bin]# ./mysql -uroot&nbsp;&nbsp; //果然不需要密码就进去了<br/>Welcome to the MySQL monitor.&nbsp;&nbsp;Commands end with ; or &#92;g.<br/>Your MySQL connection id is 2<br/>Server version: 5.7.12-log Source distribution<br/><br/>Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.<br/><br/>Oracle is a registered trademark of Oracle Corporation and/or its<br/>affiliates. Other names may be trademarks of their respective<br/>owners.<br/><br/>Type &#039;help;&#039; or &#039;&#92;h&#039; for help. Type &#039;&#92;c&#039; to clear the current input statement.<br/><br/>mysql&gt; &#92;q<br/><br/>直接mysql也成：[root@localhost x86_64]# mysql<br/>进入后密码：SET PASSWORD = PASSWORD(&#039;123456&#039;);<br/><br/>[root@localhost bin]# ./mysql -uroot <br/>Type &#039;help;&#039; or &#039;&#92;h&#039; for help. Type &#039;&#92;c&#039; to clear the current input statement.<br/>ERROR 1045 (28000): Access denied for user &#039;root&#039;@&#039;localhost&#039; (using password: NO)<br/>mysql&gt; SET PASSWORD = PASSWORD(&#039;******&#039;);<br/>Query OK, 0 rows affected, 1 warning (0.00 sec)<br/>从另一个终端登录看下，不行了，说明直接就修改了，也就是说不用flushprivilege：<br/>[root@localhost bin]# ./mysql -uroot <br/>ERROR 1045 (28000): Access denied for user &#039;root&#039;@&#039;localhost&#039; (using password: NO)<br/><br/><br/>首次参考：http://www.bubuko.com/infodetail-1173208.html<br/><br/><br/>
]]>
</description>
</item><item>
<link>http://jackxiang.com/post/8651/#blogcomment63986</link>
<title><![CDATA[[评论] [实践OK]最新mysql，[ERROR] COLLATION utf8_general_ci is not valid for CHARACTER SET latin1,及mysql-5.7.12的初始化密码放error.log了。]]></title> 
<author>cl &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Fri, 29 Apr 2016 08:39:04 +0000</pubDate> 
<guid>http://jackxiang.com/post/8651/#blogcomment63986</guid> 
<description>
<![CDATA[ 
	你好请问 这个data/logs/mysql/error.log 我找不到 我是mac系统 博主是怎么找到的
]]>
</description>
</item>
</channel>
</rss>