在 /etc下新建一个my.cnf文件,内容如下
Last login: Thu May 9 19:50:39 on ttys001
wanggonegedeAir:~ wanggonggege$ cd /private/etc
wanggonegedeAir:etc wanggonggege$ ls
afpovertcp.cfg newsyslog.conf
afpovertcp.cfg~orig newsyslog.d
aliases nfs.conf
aliases.db nfs.conf~orig
apache2 notify.conf
asl ntp.conf
asl.conf ntp_opendirectory.conf
auto_home openldap
auto_master pam.d
auto_master~orig passwd
autofs.conf paths
bashrc paths.d
bashrc_Apple_Terminal paths~orig
bashrc~previous periodic
bootpd.plist pf.anchors
com.apple.screensharing.agent.launchd pf.conf
csh.cshrc pf.os
csh.cshrc~orig php-fpm.conf.default
csh.login php-fpm.d
csh.login~orig php.ini.default
csh.logout php.ini.default-previous
csh.logout~orig postfix
cups ppp
defaults profile
dnsextd.conf profile~orig
emond.d protocols
find.codes protocols~previous
find.codes~orig racoon
fstab.hd rc.common
fstab.hd~previous rc.common~previous
ftpusers rc.netboot
ftpusers~orig resolv.conf
gettytab rmtab
gettytab~orig rpc
group rpc~previous
group~previous rtadvd.conf
hosts rtadvd.conf~previous
hosts.equiv security
hosts~orig services
irbrc services~previous
kern_loader.conf shells
kern_loader.conf~previous shells~orig
krb5.keytab snmp
localtime ssh
locate.rc ssl
mach_init.d sudo_lecture
mach_init_per_login_session.d sudoers
mach_init_per_user.d sudoers.d
mail.rc sudoers~orig
mail.rc~orig syslog.conf
man.conf syslog.conf~previous
manpaths ttys
manpaths.d ttys~previous
master.passwd wfs
master.passwd~orig xtab
nanorc zprofile
networks zshrc
networks~orig
wanggonegedeAir:etc wanggonggege$ sudo vim my.cnf
Password:
wanggonegedeAir:etc wanggonggege$ ls
afpovertcp.cfg networks~orig
afpovertcp.cfg~orig newsyslog.conf
aliases newsyslog.d
aliases.db nfs.conf
apache2 nfs.conf~orig
asl notify.conf
asl.conf ntp.conf
auto_home ntp_opendirectory.conf
auto_master openldap
auto_master~orig pam.d
autofs.conf passwd
bashrc paths
bashrc_Apple_Terminal paths.d
bashrc~previous paths~orig
bootpd.plist periodic
com.apple.screensharing.agent.launchd pf.anchors
csh.cshrc pf.conf
csh.cshrc~orig pf.os
csh.login php-fpm.conf.default
csh.login~orig php-fpm.d
csh.logout php.ini.default
csh.logout~orig php.ini.default-previous
cups postfix
defaults ppp
dnsextd.conf profile
emond.d profile~orig
find.codes protocols
find.codes~orig protocols~previous
fstab.hd racoon
fstab.hd~previous rc.common
ftpusers rc.common~previous
ftpusers~orig rc.netboot
gettytab resolv.conf
gettytab~orig rmtab
group rpc
group~previous rpc~previous
hosts rtadvd.conf
hosts.equiv rtadvd.conf~previous
hosts~orig security
irbrc services
kern_loader.conf services~previous
kern_loader.conf~previous shells
krb5.keytab shells~orig
localtime snmp
locate.rc ssh
mach_init.d ssl
mach_init_per_login_session.d sudo_lecture
mach_init_per_user.d sudoers
mail.rc sudoers.d
mail.rc~orig sudoers~orig
man.conf syslog.conf
manpaths syslog.conf~previous
manpaths.d ttys
master.passwd ttys~previous
master.passwd~orig wfs
my.cnf xtab
nanorc zprofile
networks zshrc
wanggonegedeAir:etc wanggonggege$ sudo vim my.cnf
Password:
wanggonegedeAir:etc wanggonggege$ sudo vim my.cnf
Password:
wanggonegedeAir:etc wanggonggege$ sudo vim my.cnf
wanggonegedeAir:etc wanggonggege$ mysql -uroot -p1314
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.23 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> status;
--------------
mysql Ver 8.0.13 for osx10.14 on x86_64 (Homebrew)
Connection id: 7
Current database:
Current user: root@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.7.23 MySQL Community Server (GPL)
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8
Db characterset: utf8
Client characterset: utf8
Conn. characterset: utf8
UNIX socket: /tmp/mysql.sock
Uptime: 2 min 11 sec
Threads: 3 Questions: 80 Slow queries: 0 Opens: 117 Flush tables: 1 Open tables: 110 Queries per second avg: 0.610
--------------
mysql> show variables like 'character_set_%';
+--------------------------+-----------------------------------------------------------+
| Variable_name | Value |
+--------------------------+-----------------------------------------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/local/mysql-5.7.23-macos10.13-x86_64/share/charsets/ |
+--------------------------+-----------------------------------------------------------+
8 rows in set (0.01 sec)
mysql> quit
Bye
wanggonegedeAir:etc wanggonggege$ mysql -uroot -p1314
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.7.23-log MySQL Community Server (GPL)
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show variables like 'character_set_%';
+--------------------------+-----------------------------------------------------------+
| Variable_name | Value |
+--------------------------+-----------------------------------------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/local/mysql-5.7.23-macos10.13-x86_64/share/charsets/ |
+--------------------------+-----------------------------------------------------------+
8 rows in set (0.01 sec)
mysql> status;
--------------
mysql Ver 8.0.13 for osx10.14 on x86_64 (Homebrew)
Connection id: 9
Current database:
Current user: root@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.7.23-log MySQL Community Server (GPL)
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8
Db characterset: utf8
Client characterset: utf8
Conn. characterset: utf8
UNIX socket: /tmp/mysql.sock
Uptime: 35 sec
Threads: 3 Questions: 49 Slow queries: 0 Opens: 117 Flush tables: 1 Open tables: 11 Queries per second avg: 1.400
--------------
mysql> history;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'history' at line 1
mysql> alter table db3.account convert to character set utf8 collate utf8_general_ci;
Query OK, 6 rows affected (0.05 sec)
Records: 6 Duplicates: 0 Warnings: 0
mysql> alter database db3 default character set utf8 collate utf8_general_ci;
Query OK, 1 row affected (0.02 sec)
mysql> quit
Bye
wanggonegedeAir:etc wanggonggege$ sudo vim my.cnf
Password:
# Example MySQL config file for medium systems.
#
# This is for a system with little memory (32M - 64M) where MySQL plays
# an important part, or systems up to 128M where MySQL is used together with
# other programs (such as a web server)
#
# MySQL 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, see:
# 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 MySQL clients
[client]
default-character-set=utf8
#password = your_password
port = 3306
socket = /tmp/mysql.sock
# Here follows entries for some specific programs
# The MySQL server
对在修改mysql配置文件之前,你已经存在的数据库,如果你想要输入中文字段,请对该数据库进行如下修改:
mysql -u 用户名 -p
输入密码
进入mysql
对数据库的表进行更改(此时表的字体还不是utf8)
终端进入mysql
alter table 数据库名.表名 convert to character set utf8 collate utf8_general_ci;
最后对数据库进行修改
alter database 数据库名 default character set utf8 collate utf8_general_ci;
捣鼓这个鬼东西捣鼓了三个小时,差点心态爆炸了。
这样子以后,发现JDBC对数据库的操作,或者是workbench对数据库进行中文字段的操作,都可以成功!!!