1 MySqL服务器启动问题
1.1 mysal连接时报2003错误
1.1.1 原因:MySQL服务器没有启动
1.1.2 没有MySQL服务器的解决(安装MySQL服务):
-
cmd中mysql的bin目录下用mysqld.exe –install命令
-
如果提示Install/Remove of the Service Denied!就是权限不够:用管理员身份运行cmd
1.1.3 安装成功:
1.2 服务器启动不了(1067错误)
如图:
1.2.1 原因:
• 应该是把mysql自带的数据库mysql、test删了,导致所需的mysql.user文件。
1.2.2 解决方法:
• 因为用的是解压版,就从该压缩文件里把被删掉的补回去;
• 再在cmd里依次执行mysqld.exe –install(初始化)、net start mysql(启动服务器)
1.2.3 结果:
1.2.4 注意:
• 因为之前看网上有的改ini或者新建my.ini代替my-default.ini成功了,但是在我这里不行,要把改的删掉用原本的ini,才能执行cmd。
• 改完后默认密码为空,之前设置的密码就不能用了
2 idea里与sql语句有关的报错
2.1 用Mybatis+Spring时,报错:TypeException: Error setting non null for parameter #1 with JdbcType null .
2.1.1 原因:Mapper.xml里有注解(或sql语句的’’加错地方)
如图:
2.1.2 解决方法:
• 删除该注解即可
3 SQLyog字符编码修改
3.1 问题:表中插入的数据为中文时会显示成??
3.1.1 原因:默认的字符编码不是utf8
3.1.2 解决方法:
• 单表:右击要改的表,修改表结构,取消勾选隐藏字符编码(表单-改变表),字符集:utf8,核对:utf8_general_ci
• 多表(一次性):数据库-改变数据库,字符集:utf8,核对:utf8_general_ci
3.2 问题:从服务端到数据库的数据里中文显示??
3.2.1 原因:两边用的字符编码不一样
3.2.2 解决方法:
• 在jdbc连接数据库时加上?characterEncoding=UTF-8
•
4 数据库连接问题
4.1 不显示新建的数据库
原因:新建连接时指定了数据库,如下,所以不指定就好了
5 mysql里的varchar
与Oracle不同在mysql里varchar(12)后的12是指字符,而Oracle里要除以3.
改密
C:\Users\Administrator>cd /dD:\install\mysql-5.6.27-winx64\bin
进入D盘mysql安装路径里
D:\install\mysql-5.6.27-winx64\bin>mysql
启动MySQL
Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.6.27 MySQL Community Server (GPL) Copyright (c) 2000, 2015, 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 DATABASES;
mysql> use test
进入test数据库
Database changed
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456'; 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 'IDENTIFIED BY '123456'' at line 1 mysql> set password for root@localhost = password('123456'); ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql' mysql> SET PASSWORD = '123456'; ERROR 1133 (42000): Can't find any matching row in the user table mysql> quit Bye
各种修改密码的方法:
有用的方法1:
-
找到配置文件my.ini ,然后将其打开,可以选择用NotePadd++打开
-
在[mysqld]下面添加skip-grant-tables(随便哪行都可以),保存退出。
-
登录MySQL不管password
D:\install\mysql-5.6.27-winx64\bin>mysql -u root –p Enter password:
。。。登录成功
mysql> use test
进入test数据库
Database changed mysql> update mysql.user set authtntication_string=password('123456') where user='root'; ERROR 1054 (42S22): Unknown column 'authtntication_string' in 'field list' 没有authtntication_string这个字段,改成password: mysql> update mysql.user set password=password('123456') where user='root'; Query OK, 3 rows affected (0.01 sec) Rows matched: 3 Changed: 3 Warnings: 0
刷新数据库
mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
退出后删除配置文件my.ini中[mysqld]下面添加的skip-grant-tables
mysql> quit; Bye
重新登录
D:\install\mysql-5.6.27-winx64\bin>mysql -u root -p Enter password: ******
输入密码
。。。登录成功
mysql>
当上面的方法没用时(方法2):
- 原因: mysql> update mysql.user set password='123456'where User='root';
出现ERROR 1142 (42000): UPDATE command denied to user ''@'localhost' for table 'user'错误。
- 解决方法如下:
进入mysql/bin目录,执行mysqladmin -uroot password 会提示输入新密码;
之后,再用新密码登录:mysql -uroot -p 回车passwd:输入密码
- 如图: