Modify the MySQL encoding format under mac terminal -- cannot find the my-default.cnf and my. cnf, cannot find mydefault. cnf

Source: Internet
Author: User

Modify the MySQL encoding format under mac terminal -- cannot find the my-default.cnf and my. cnf, cannot find mydefault. cnf

First, make sure that MySQL is correctly installed.

1-configure the environment variable path first

1.1 open the terminal and enter: cd ~

Will enter ~ Folder,

1.2 then enter: touch. bash_profile

After you press enter to execute,

1.3 enter: open-e. bash_profile

This file will be opened in TextEdit (if environment variables have not been configured before, this should be a blank document ).

If there is content, enter it before the Terminator. If there is no content, enter the following statement:

Export PATH =$ {PATH}:/usr/local/mysql/bin

Then, save and exit TextEdit (it must be quit), close the terminal, and exit.

In this case, you can directly log on to MySQL using the following statement:

> Mysql-uroot-p

1.4 close MySQL !!!! (Disable MySQL in system preference settings)

2-The point is coming !!!

2.1 check the support-files folder ("go to folder" under Finder; Path:/usr/local/mysql/support-files)

There is no my-default.cnf or my. cnf file... if there is, open the Add directly

Add default-character-set = utf8 under [client]. The default character set is utf8.
Add in [mysqld]
Default-character-set = utf8 default character set: utf8
Init_connect = 'set NAMES utf8' (SET utf8 encoding for connecting to the mysql database to run utf8) after modification, restart mysql to view the current data encoding format. > Show variables like '% char %'; + -------------------------- + ---------------------------- +
| 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/share/mysql/charsets/|
+ -------------------------- + ---------------------------- +

If the terminal displays the above style, it will be OK; otherwise, continue to look at it:

2.2 support-files folder contains no my-default.cnf or my. cnf file, you need to create my. cnf under/etc

$ Cd/etc

$ Sudo vim my. cnf

2.3 After completing the previous step, the vim mode is displayed. Copy the (*** text) content and paste it in (excluding *** text );

2.4 check whether the first line of vim "#" has been lost after the paste is successful (I have lost it myself ~~ Haha ~), If all are OK, click esc to exit editing,

: Wq! -- Force exit after saving. [add several edit commands: dd to delete the row where the cursor is located; dw to delete a word; x to delete the current character].

 

(*** Text ):

 

# Example MySQL config file for medium systems.
#
# This is for a system with little memory (32 M-64 M) where MySQL plays
# An important part, or systems up to 128 M where MySQL is used together
# Other programs (such as a web server)
#
# MySQL programs look for option files in a set
# 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
[Mysqld]
Character-set-server = utf8
Init_connect = 'set NAMES utf8
Port = 3306
Socket =/tmp/mysql. sock
Skip-external-locking
Key_buffer_size = 16 M
Max_allowed_packet = 1 M
Table_open_cache = 64
Sort_buffer_size = 512 K
Net_buffer_length = 8 K
Read_buffer_size = 256 K
Read_rnd_buffer_size = 512 K
Myisam_sort_buffer_size = 8 M
Character-set-server = utf8
Init_connect = 'set NAMES utf8'
# Don't listen on a TCP/IP port at all. This can be a security enhancement,
# If all processes that need to connect to mysqld run on the same host.
# All interaction with mysqld must be made via Unix sockets or named pipes.
# Note that using this option without enabling named pipes on Windows
# (Via the "enable-named-pipe" option) will render mysqld useless!
#
# Skip-networking

# Replication Master Server (default)
# Binary logging is required for replication
Log-bin = mysql-bin

# Binary logging format-mixed recommended
Binlog_format = mixed

# Required unique id between 1 and 2 ^ 32-1
# Defaults to 1 if master-host is not set
# But will not function as a master if omitted
Server-id = 1

# Replication Slave (comment out master section to use this)
#
# To configure this host as a replication slave, you can choose
# Two methods:
#
#1) Use the change master to command (fully described in our manual )-
# The syntax is:
#
# Change master to MASTER_HOST = # MASTER_USER = <user>, MASTER_PASSWORD = <password>;
#
# Where you replace # <Port> by the master's port number (3306 by default ).
#
# Example:
#
# Change master to MASTER_HOST = '192. 564.12.1 ', MASTER_PORT = 125,
# MASTER_USER = 'job', MASTER_PASSWORD = 'secret ';
#
# OR
#
#2) Set the variables below. However, in case you choose this method, then
# Start replication for the first time (even unsuccessfully, for example
# If you mistyped the password in master-password and the slave fails
# Connect), the slave will create a master.info file, and any later
# Change in this file to the variables 'values below will be ignored and
# Overridden by the content of the master.info file, unless you shutdown
# The slave server, delete master.info and restart the slaver server.
# For that reason, you may want to leave the lines below untouched
# (Commented) and instead use change master to (see above)
#
# Required unique id between 2 and 2 ^ 32-1
# (And different from the master)
# Defaults to 2 if master-host is set
# But will not function as a slave if omitted
# Server-id = 2
#
# The replication master for this slave-required
# Master-host = #
# The username the slave will use for authentication when connecting
# To the master-required
# Master-user = <username>
#
# The password the slave will authenticate with when connecting
# The master-required
# Master-password = <password>
#
# The port the master is listening on.
# Optional-defaults to 3306
# Master-port = <port>
#
# Binary logging-not required for slaves, but recommended
# Log-bin = mysql-bin

# Uncomment the following if you are using InnoDB tables
# Innodb_data_home_dir =/usr/local/mysql/data
# Innodb_data_file_path = ibdata1: 10 M: autoextend
# Innodb_log_group_home_dir =/usr/local/mysql/data
# You can set .. _ buffer_pool_size up to 50-80%
# Of RAM but beware of setting memory usage too high
# Innodb_buffer_pool_size = 16 M
# Innodb_additional_mem_pool_size = 2 M
# Set .. _ log_file_size to 25% of buffer pool size
# Innodb_log_file_size = 5 M
# Innodb_log_buffer_size = 8 M
# Innodb_flush_log_at_trx_commit = 1
# Innodb_lock_wait_timeout = 50

[Mysqldump]
Quick
Max_allowed_packet = 16 M

[Mysql]
No-auto-rehash
# Remove the next comment character if you are not familiar with SQL
# Safe-updates
Default-character-set = utf8

[Myisamchk]
Key_buffer_size = 20 M
Sort_buffer_size = 20 M
Read_buffer = 2 M
Write_buffer = 2 M

[Mysqlhotcopy]
Interactive-timeout

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.