乱码问题:
#vim /etc/mysql/my.cnf 。(5.5以后系统)如下修改:
[client]
default-character-set=utf8
[mysqld]
default-storage-engine=INNODB
character-set-server=utf8
collation-server=utf8_general_ci
1、创建数据库的时候:CREATE DATABASE `test`
CHARACTER SET 'utf8'
COLLATE 'utf8_general_ci';
2、建表的时候 CREATE TABLE `database_user` (
`ID` varchar(40) NOT NULL default '',
`UserID` varchar(40) NOT NULL default '',
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
show variables like "%char%";
数据库远程连接
1
use mysql;
select host,user,password from user;
Grant all privileges on *.* to 'root'@'%' identified by 'password' with grant option;
flush privileges;
2找到mysql的配置文件my.cnf,把bind address修改这台机器的真实IP就可以了
或者直接把bind address这一项注释掉也行。需要重启才能生效
mysql5.7忘记root密码:
1.修改mysql配置文件
#vim /etc/my.cnf
skip-grant-tables
2.登录mysql
use mysql;
update mysql.user set authentication_string=password('centrald') where user='root' and Host = 'localhost';
FLUSH PRIVILEGES;
3.重新启动mysql也成功
mysql登录后,提示修改密码
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> set PASSWORD=Password('root');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> alter user root@localhost PASSWORD EXPIRE NEVER;
Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)
密码修改成功,密码也不提示过期了。