mysql数据库的初始化配置

来源:互联网 发布:虚拟机的三种网络模式 编辑:程序博客网 时间:2024/05/16 17:51

1.配置端口:My.ini

三处地方:

# The following options will be passed to all MySQL clients
[client]
#password = your_password
port = 3306
socket = /tmp/mysql.sock


# Here follows entries for some specific programs


# The MySQL server
[wampmysqld]
port = 3306
socket = /tmp/mysql.sock

[mysqld]
port=3306
explicit_defaults_for_timestamp = TRUE


2.配置字符集:

a.查询默认字符集的方法:

   • SHOW CHARACTER SET;
    • SHOW COLLATION;
    • SHOW VARIABLES LIKE ‘character%’;
    • SHOW VARIABLES LIKE ‘collation%’;

    • \s;

b.修改的方法:

 set character_set_client=utf8;
 set character_set_connection=utf8;
 set character_set_database=utf8;
 set character_set_results=utf8;
 set character_set_server=utf8;
 set character_set_system=utf8;
 set collation_connection=utf8;
set collation_database=utf8;
 set collation_server=utf8;

c.修改某个特定数据库的方法:

创建数据库指定数据库的字符集
create database mydb character set utf8;

修改数据库的字符集

mysql>use mydb
alter database mydb character set utf8;


d.Java调用URL字符串:

1.request.setCharacterEncoding("utf8");
 response.setContentType("text/html charset=utf8");
2.在安装数据库的地方找到my.ini并设置default-character-set=utf8有两处
3.String URL = "jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8"; 
4.服务器默认编码 web.xml中


3.修改mysql默认的密码:

grant all privileges on *.* to 'root'@'localhost' identified by 'new password';
flush privileges;
\r(重启一个连接)


4.命令行登陆


set names utf8;




1 0