Centos mysql5.7 installation problems: change the default password, modify the code, start abnormal

After installing mysql modify the default password

After mysql5.7 installed, it will generate a random password, random password in mysql's error log,
viewed through this command or

grep 'temporary password' /var/log/mysqld.log 
##会显示如下
A temporary password is generated for root@localhost: wcjSqexWh6&T

Which wcjSqexWh6 & T is the default password, you can use this password to modify the login
command to change the login is:

#5.7之后只能通过这种方式修改,以前的update和set方式不可用了
mysql>ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';

Restart mysql after editing, you can use the new password.

Modify codes encountered pit

After creating the database, to start construction of the table, inser data to try a few hands, when you insert data, found it impossible to insert the Chinese, because the default database encoding is not utf-8, does not support Chinese, you can view the encoded using the following command:

mysql>show variables like 'char%';
#我的数据库默认是latin1的编码格式

In order to support the Chinese, it is necessary to modify the coding of the database table, the database in order to facilitate future I also changed the coding
modifications:

#修改数据库编码
alter database <数据库名> character set utf8;
#修改表编码
alter table <表名> character set utf8;
#还需要修改相应字段的编码
alter table <表名> change <字段名> <字段名> <类型> character set utf8;
#例子
mysql>alter table student change name name varchar(140) character set utf8;

Tip: The best time to specify the encoding in the construction of the table

Pit ->

Online article said /etc/my.cnf to modify the file, once and for all solve the problem
together under [mysqld] tag
default = utf8 the SET-Character-
Character-the SET-Server = utf8
two labels, I would have been such a change but after he discovered how also does not start up, check the check error log,
found that 5.7 does not support no longer support default-character-set = utf8 this property:

[ERROR] /usr/sbin/mysqld: unknown variable 'default-character-set=utf8'

Deleted after the restart, the perfect solution (online articles are a great copy, pit plenty of money).
Tip: Find the error log when, in order to quickly locate the problem can be [ERROR] filter

Published 17 original articles · won praise 12 · views 10000 +

Guess you like

Origin blog.csdn.net/qq_24295537/article/details/93424168