First, make sure that MySQL is properly installed.
1-Configure the environment variable path first
1.1 Open terminal, input: CD ~
Will enter the ~ folder,
1.2 then enter:touch. Bash_profile
After the carriage return is executed,
1.3 Re-enter:open-e. Bash_profile
This file is opened in TextEdit (this should be a blank document if the environment variable has not been previously configured).
If you have content, enter it before the Terminator, and if there is no content, enter the following statement directly:
Export Path=${path}:/usr/local/mysql/bin
Then, save, Exit TextEdit (must be exited), close the terminal and exit.
You should now be able to log in to MySQL directly with the following statement
>mysql-uroot-p
1.4 Turn off MySQL!!!! (Turn MySQL off in System Preferences)
2-The emphasis came!!!
2.1 View the Support-files folder ("Go to Folder" under Finder; path:/usr/local/mysql/support-files)
There are no my-default.cnf or my.cnf files ... If available, open the add directly
Under [client], add the Default-character-set=utf8 default character set to UTF8
Add in [mysqld]
Default-character-set=utf8 default character set is UTF8
init_connect= ' Set NAMES UTF8 ' (when setting up a MySQL database using UTF8 encoding to let the MySQL database run for UTF8), 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 appears as the upper style is OK, otherwise continue to look down:
2.2 Support-files Folder There is no my-default.cnf or my.cnf file, then you need to create a new my.cnf in/etc
$ cd/etc
$ sudo vim my.cnf
2.3 After the last step will enter the VIM mode, at this time copy (* * * text) content pasted in, (does not contain * * * text);
2.4 Paste success after the attention to see the first line of vim "#" has not lost (I have lost ~ ~ haha ~), all OK, click ESC Exit Edit,
: wq! --force exit after saving. [With several editing commands:DD Delete the line of the cursor; DW Deletes a word (word); x Delete the current character].
(* * * text):
# Example MySQL config file for medium systems.
#
# This was 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.
# can copy this option file to one of those
# locations. For information on these locations, see:
# http://dev.mysql.com/doc/mysql/en/option-files.html
#
# In the This file, you can use the all long options, which a program supports.
# If you want to know which options a program supports, run the program
# with the "--help" option.
# The following options would 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 = 16M
Max_allowed_packet = 1M
Table_open_cache =
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
Character-set-server=utf8
init_connect= ' SET NAMES UTF8 '
# Don ' t listen on a TCP/IP port at all. This can is a security enhancement,
# If all processes this need to connect to mysqld run on the same host.
# All interaction with Mysqld must is made via Unix sockets or named pipes.
# Note that the using this option without enabling named Pipes on Windows
# (via the "enable-named-pipe" option) would 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 are not set
# but would not function as a master if omitted
Server-id = 1
# Replication Slave (Comment out Master sections to use this)
#
# To configure the host as a replication slave, you can choose between
# methods:
#
# 1) Use the Change MASTER to command (fully described with our manual)-
# The syntax is:
#
# change MASTER to Master_host=
# master_user=<user>, master_password=<password>;
#
# where you replace the
# <port> by the master's port number (3306 by default).
#
# Example:
#
# change MASTER to master_host= ' 125.564.12.1 ', master_port=3306,
# master_user= ' Joe ', master_password= ' secret ';
#
# OR
#
# 2) Set the variables below. However, in case you choose the 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 to
# Connect), the slave would create a master.info file, and any later
# change in this file to the variables ' values below 'll 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 this reason, 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 would not function as a slave if omitted
#server-id = 2
#
# The replication Master for this slave-required
#master-host =
#
# The username the slave would use for authentication when connecting
# to the master-required
#master-user = <username>
#
# The password The slave would authenticate with when connecting to
# 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 is using InnoDB tables
#innodb_data_home_dir =/usr/local/mysql/data
#innodb_data_file_path = Ibdata1:10m: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 = 16M
#innodb_additional_mem_pool_size = 2M
# Set: _log_file_size to% of buffer pool size
#innodb_log_file_size = 5M
#innodb_log_buffer_size = 8M
#innodb_flush_log_at_trx_commit = 1
#innodb_lock_wait_timeout =
[Mysqldump]
Quick
Max_allowed_packet = 16M
[MySQL]
No-auto-rehash
# Remove The next comment character if you is not a familiar with SQL
#safe-updates
Default-character-set=utf8
[Myisamchk]
Key_buffer_size = 20M
Sort_buffer_size = 20M
Read_buffer = 2M
Write_buffer = 2M
[Mysqlhotcopy]
Interactive-timeout
Edit MySQL encoding format under Mac Terminal--my-default.cnf and my.cnf not found