MySQL配置

zip方式安装5.7.16版本的MySQL

  1. 解压:例如解压到D:\MySQL
  2. 配置环境变量:系统属性-高级-环境变量,编辑PATH变量,添加D:\MySQL\mysql-5.7.16winx64\bin
  3. 修改配置文件:复制D:\MySQL\mysql-5.7.16winx64目录下的my-default.ini文件为my.ini文件,

    修改#basedir = 为 basedir = D:\MySQL\mysql-5.7.16winx64
    修改#datadir = 为 datadir = D:\MySQL\mysql-5.7.16winx64\data
    在[mysqld]下增加character_set_server=utf8
    在[client]下增加port=3306
    character_set_server=utf8

  4. 安装:管理员权限执行cmd,进入上述bin文件夹,输入

mysqld install MySQL --defaults-file="D:\MySQL\mysql-5.7.16winx64\my.ini"
  1. 初始化:提示安装服务成功 Service successfully installed后初始化,输入
mysqld --initialize

接着启动MySQL服务

 net start mysql

6.连接数据库: 输入 mysql -uroot -p,显示Enter password:输入密码,初始密码可在D:\MySQL\mysql-5.7.16winx64\data目录下错误日志文件(后缀.err)找到
7. 修改密码:输入mysql -u root 后输入SET PASSWORD FOR ‘root’@’localhost’ = PASSWORD(‘newpass’); 可以将密码修改为newpass

修改编码

主要包括四方面:Server,DataBase,Client,Connection

  1. 启动、登录、查看数据库
  2. \s命令查看编码
  3. 设置编码:mysql> set character_set_client=utf8;
    mysql> set character_set_connection=utf8;
    mysql> set character_set_database=utf8;
    mysql> set character_set_results=utf8;
    mysql> set character_set_server=utf8;
    mysql> set character_set_system=utf8;
    mysql> set collation_connection=utf8;
    mysql> set collation_database=utf8;
    mysql> set collation_server=utf8;

workbench

异常Cause: Java.sql.SQLException: Incorrect string value: ‘\xE5’ for column ‘_dt’ at row 1

MySQL的默认编码是Latin1,在创建数据库时,指定字符集utf-8:
create database mydb character set utf8 ;

eclipse建立connection后,打开Sample Contents报错

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 ‘OPTION SQL_SELECT_LIMIT=26’ at line 1
错误原因:mysql版本与jdbc驱动版本不匹配,

你可能感兴趣的:(mysql)