MySQL安装再折腾--编码的设置

一、MySQL的安装

  从官网(https://dev.mysql.com/downloads/mysql/)中下载Mac OS X 10.12 (x86, 64-bit), DMG Archive(mysql-5.7.19-macos10.12-x86_64.dmg)版,双击按提示安装,安装完成后可在控制面板下启动关闭MySQL服务器,

  同时安装客户端:MySQL Workbench.app,(下载链接:https://dev.mysql.com/downloads/file/?id=468289)

  启动MySQL服务器,打开MySQL Workbench,输入初始密码,随即提示修改初始密码。

二、设置Terminal下登录路径:

  在/Users/**/新建文件:.bash_profile

  文件中输入:

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

  保存即可。在Terminal下,即可使用"mysql -u root -p"进行登录。

三、数据库编码问题

在Terminal中登录MySQL客户端(mysql -u root -p)查看数据库编码,命令如下:

mysql> SHOW VARIABLES LIKE ‘char%‘;

  发现

character_set_database | latin1

character_set_server | latin1

  需要进行编码设置,但安装文件里无my.cnf文件,网上很多解决方法都没用,只能自建my.cnf文件。

  关闭MySQL服务器,使用MacVim创建my.cnf,输入内容为:

# 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
  [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 = 64
  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 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 between
    # two methods :
    #
    # 1) Use the CHANGE MASTER TO command (fully described in our manual) -
    #    the syntax is:
    #
    #    CHANGE MASTER TO MASTER_HOST=<host>, MASTER_PORT=<port>,
    #    MASTER_USER=<user>, MASTER_PASSWORD=<password> ;
    #
    #    where you replace <host>, <user>, <password> by quoted strings and
    #    <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 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 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     =   <hostname>
    #
    # 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 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 are 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 25 % 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 = 50  

        [mysqldump]
        quick
        max_allowed_packet = 16M  

          [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 = 20M
        sort_buffer_size = 20M
        read_buffer = 2M
        write_buffer = 2M  

          [mysqlhotcopy]
          interactive-timeout

    保存并将文件存在至/etc/目录之下,重启mysql服务器,即修改成功,

如果还是不能插入汉字,请重新创建数据库和表。

参考:http://www.jianshu.com/p/628bcf8bb557

时间: 2024-11-10 13:27:06

MySQL安装再折腾--编码的设置的相关文章

MySQL基础配置之mysql的默认字符编码的设置(my.ini设置字符编码) (转)

MySQL基础配置之mysql的默认字符编码的设置(my.ini设置字符编码) MySQL的默认编码是Latin1,不支持中文,那么如何修改MySQL的默认编码呢,下面以设置UTF-8为例来说明. MySQL的默认编码是Latin1,不支持中文,那么如何修改MySQL的默认编码呢,下面以UTF-8为例来说明 需要注意的是,要修改的地方非常多,相应的修改方法也很多.下面是一种最简单最彻底的方法: 一.Windows系统下面 1.中止MySQL服务 2.在MySQL的安装目录下找到my.ini,如果

MySQL基础配置之mysql的默认字符编码的设置(my.ini设置字符编码) - 转载

MySQL基础配置之mysql的默认字符编码的设置(my.ini设置字符编码) MySQL的默认编码是Latin1,不支持中文,那么如何修改MySQL的默认编码呢,下面以设置UTF-8为例来说明. 需要注意的是,要修改的地方非常多,相应的修改方法也很多.下面是一种最简单最彻底的方法: 一.Windows系统 1.中止MySQL服务 2.在MySQL的安装目录下找到my.ini,如果没有就把my-medium.ini复制为一个my.ini即可 3.打开my.ini以后,在[client]和[mys

mysql安装 卸载 查字符集编码

下载地址 :     https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.11-winx64.zip 解压zip  解压完之后的目录 在里面新建一个my.ini文件  文件内容如下 [mysql]  # 设置mysql客户端默认字符集  default-character-set=utf8  [mysqld]  #设置3306端口  port = 3306  # 设置mysql的安装目录  basedir=D:/java/software/m

MySQL安装图解

一.MYSQL的安装 1.打开下载的mysql安装文件mysql-5.5.27-win32.zip,双击解压缩,运行"setup.exe". 2.选择安装类型,有"Typical(默认)"."Complete(完全)"."Custom(用户自定义)"三个选项,选择"Custom",按"next"键继续. 3.点选"Browse",手动指定安装目录. 4.填上安装目录,

Java基础学习笔记二十四 MySQL安装图解

.MYSQL的安装 1.打开下载的mysql安装文件mysql-5.5.27-win32.zip,双击解压缩,运行“setup.exe”. 2.选择安装类型,有“Typical(默认)”.“Complete(完全)”.“Custom(用户自定义)”三个选项,选择“Custom”,按“next”键继续. 3.点选“Browse”,手动指定安装目录. 4.填上安装目录,我的是“F:\Server\MySQL\MySQL Server 5.0”,也建议不要放在与操作系统同一分区,这样可以防止系统备份还

Windown安装Mysql安装图解

一.MYSQL的安装 1.打开下载的mysql安装文件mysql-5.0.27-win32.zip,双击解压缩,运行“setup.exe”. 2.选择安装类型,有“Typical(默认)”.“Complete(完全)”.“Custom(用户自定义)”三个选项,选择“Custom”,按“next”键继续. 3.在“Developer Components(开发者部分)”上左键单击,选择“This feature, and all subfeatures, will be installed on

MYSQL 安装教程二

Mysql是一款功能强大的数据库软件,Mysql安装图文教程将介绍如何安装Mysql,接下来一起了解一下Mysql是如何安装的吧. MySQL - MySQL服务器.你需要该选项,除非你只想连接运行在另一台机器上的MySQL服务器.MySQL-client - MySQL 客户端程序,用于连接并操作Mysql服务器.MySQL-devel - 库和包含文件,如果你想要编译其它MySQL客户端,例如Perl模块,则需要安装该RPM包.MySQL-shared - 该软件包包含某些语言和应用程序需要

MYSQL安装以及卸载 -- WINDOWS

mySQL可以去官网下载对应的版本进行安装,这里采用的版本为"mysql-5.5.40-win64.msi"; 安装 1.双击"mysql-5.5.40-win64.msi",进入安装页面. 进入此界面之前会出现等待的界面,此处需耐心等待一会. 2.同意协议,next. 3.选择安装类型 安装类型有"Typical(默认)"."Complete(完全)"."Custom(用户自定义)"三个选项,选择&quo

MySQL安装最后一步无响应解决方法

一.卸载及安装 MySQL安装到最后一步就卡住,如图: 卸载原来安装的MySQL1.首先,卸载MySQL:2.然后,删除C盘下(C:\ProgramData\MySQL)文件: 然后重新安装MySQL,但是,这里要注意了,安装图1中时不要勾上(Launch the Mysql instance configuration wizard 不要勾上),直接单击“Finish”按钮.     安装完毕后,我们打开MySQL安装路径,这里我安装在D:\Program Files\MySQL.然后找到bi