您的位置:首页 > 数据库 > MySQL

mysql常见操作汇总

2015-07-25 19:25 821 查看
1、Mysql服务突然启不来了,报错:



在分析时发现
MySQL Server 5.0\data下面有个名称为用户名,扩展名为.err的文件:

150725 20:01:19 [Note] 自己的安装目录\MySQL\MySQL Server 5.0\bin\mysqld-nt: Shutdown complete

150725 21:26:35  InnoDB: Error: unable to create temporary file; errno: 9
150725 21:26:35 [ERROR] Default storage engine (InnoDB) is not available
150725 21:26:35 [ERROR] Aborting

150725 21:26:35 [Note] 自己的安装目录\MySQL\MySQL Server 5.0\bin\mysqld-nt: Shutdown complete


按照网上找的解决办法,
(1)在MySQL\MySQL Server 5.0\my.ini中增加配置
tmpdir="自己的安装目录/MySQL/MySQL Server 5.0/Temp"

(2)更改引擎:
# The default storage engine that will be used when create new tables when
#default-storage-engine=INNODB
default-storage-engine=MyISAM

后,重新启动MySQL服务即可。

成功启动后 MySQL Server 5.0\data\当前用户名.err中的内容如下:

150725 20:01:19 [Note] C:\Program Files\MySQL\MySQL Server 5.0\bin\mysqld-nt: Shutdown complete

150725 21:26:35  InnoDB: Error: unable to create temporary file; errno: 9
150725 21:26:35 [ERROR] Default storage engine (InnoDB) is not available
150725 21:26:35 [ERROR] Aborting

150725 21:26:35 [Note] C:\Program Files\MySQL\MySQL Server 5.0\bin\mysqld-nt: Shutdown complete

150725 21:28:12  InnoDB: Error: unable to create temporary file; errno: 9
150725 21:28:12 [Note] C:\Program Files\MySQL\MySQL Server 5.0\bin\mysqld-nt: ready for connections.
Version: '5.0.96-community-nt'  socket: ''  port: 3306  MySQL Community Edition (GPL)


从上面的信息可以看到temporary file仍然创建失败,但Mysql服务器启动成功了



mysql> show engines;
+------------+----------+----------------------------------------------------------------+
| Engine     | Support  | Comment
+------------+----------+----------------------------------------------------------------+
| MyISAM     | DEFAULT  | Default engine as of MySQL 3.23 with great performance
| MEMORY     | YES      | Hash based, stored in memory, useful for temporary tables      |
| InnoDB     | DISABLED | Supports transactions, row-level locking, and foreignkeys     |
| BerkeleyDB | NO       | Supports transactions and page-level locking
| BLACKHOLE  | YES      | /dev/null storage engine (anything you write to it disappears) |
| EXAMPLE    | NO       | Example storage engine
| ARCHIVE    | YES      | Archive storage engine
| CSV        | NO       | CSV storage engine
| ndbcluster | NO       | Clustered, fault-tolerant, memory-based tables
| FEDERATED  | YES      | Federated MySQL storage engine
| MRG_MYISAM | YES      | Collection of identical MyISAM tables
| ISAM       | NO       | Obsolete storage engine
+------------+----------+----------------------------------------------------------------+
12 rows in set (0.00 sec)


2、MySQL 参数autoReconnect=true 解决8小时连接失效
(1). 即使在创建Mysql时url中加入了autoReconnect=true参数,一但这个连接两次访问数据库的时间超出了服务器端wait_timeout的时间限制,还是会CommunicationsException: The last packet successfully received from the server was xxx milliseconds ago.
(2) 服务器端的参数可以用
show global variables like 'wait_timeout';



28800s=8h
set global wait_timeout=10;
来进行设置,但是wait_timeout值不应该设的太高.
(3). 较好的策略是对处于idle状态的connection定时发送一个sql,来刷新服务器上的时间戳.这可以使用c3p0r的连接池.http://bzhang.iteye.com/blog/321832
(4). 对于tomcat的server.xml中使用的连接池,http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.html,http://commons.apache.org/dbcp/configuration.html使用DBCP的连接池可以采用

<Resource name="jdbc/test" auth="Container"
type="javax.sql.DataSource" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/test?characterEncoding=utf-8"
username="root" password="test" maxActive="500" maxIdle="10"
maxWait="-1" timeBetweenEvictionRunsMillis="10000" minEvictableIdleTimeMillis="10000" />


4.1 设置validationQuery,这样每次borrow(默认为开启)时会通过这个sql校验连接的有效性,但是增加了时间.
4.2 设置timeBetweenEvictionRunsMillis="10000" minEvictableIdleTimeMillis="10000" 依赖evictor thread线程来把超时的连接关闭.
4.3 设置testWhileIdle="true" timeBetweenEvictionRunsMillis="10000" validationQuery="select 1" 使得定时去用query检测处于idle状态的连接,也就刷新了服务器端的时间.

(5).每次提交的最大packet大小 show global variables like 'max_allowed_packet'; set global max_allowed_packet=1024*1024;
http://www.linuxidc.com/Linux/2012-10/72245.htm
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password

mysql ERROR 1045 (28000): Access denied for user解决方法

问题重现(以下讨论范围仅限Windows环境):

C:\AppServ\MySQL> mysql -u root -p Enter password: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

编辑mysql配置文件my.ini(不知道在哪请搜索),在[mysqld]这个条目下加入 skip-grant-tables 保存退出后重启mysql

1.点击“开始”->“运行”(快捷键Win+R)。
2.启动:输入 net stop mysql
3.停止:输入 net start mysql

这时候在cmd里面输入mysql -u root -p就可以不用密码登录了,出现password:的时候直接回车可以进入,不会出现ERROR 1045 (28000),但很多操作都会受限制,因为我们不能grant(没有权限)。按下面的流程走(红色部分为输入部分,粉红色的是执行后显示的代码不用输入):

1.进入mysql数据库:

mysql> use mysql; Database changed

2.给root用户设置新密码,蓝色部分自己输入:
mysql> update user set password=password("新密码") where user="root";
Query OK, 1 rows affected (0.01 sec) Rows matched: 1 Changed: 1 Warnings: 0

3.刷新数据库
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

4.退出mysql:
mysql> quit Bye

改好之后,再修改一下my.ini这个文件,把我们刚才加入的"skip-grant-tables"这行删除,保存退出再重启mysql就可以了。
http://blog.csdn.net/hsg77/article/details/39159191
在windows平台下MySql启动时的1067错误的解决方法及反思

一、

1、打开my.ini文件,找到default-storage-engine=InnoDB这一行,把它改成default-storage-engine=MyISAM。

2、删除在MySQL安装目录下的Data目录中的ib_logfile0和ib_logfile1 3。找到在配置MySQL服务器时指定的InfoDB目录删除掉ibdata1

根据my.ini文件中:

#*** INNODB Specific options *** innodb_data_home_dir="D:/"。 4。重新启动MySQL的Service

根据我自己的实践,只要进行第三步就能解决问题。

二、

err文件内容:

090417 9:02:55 InnoDB: Error: unable to create temporary file; errno: 2 090417 9:02:55 [ERROR] Plugin 'InnoDB' init function returned error. 090417 9:02:55 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed. 090417 9:02:55 [ERROR] Unknown/unsupported table type: INNODB 090417 9:02:55 [ERROR] Aborting

090417 9:02:55 [Warning] Forcing shutdown of 1 plugins 090417 9:02:55 [Note] MySQL: Shutdown complete

经过一翻Google,找出了无法启动的原因:MySQL在安装的时候不会自动初始tmpdir(临时文件目录),所以要在配置文件my.ini中添加如下内容:

[mysqld]

#自己指定的临时文件目录

tmpdir="D:/MySQL/MySQL Server 5.1/Temp"

再次启动MySQL一切正常,在Temp文件夹下生成了一些*.tmp的临时文件。

最后还是存在一些疑问:如果是由于没有初始化tmpdir,为什么在我第一次安装的时候也没有初始化,但也没有出现这样的问题?

三、

以前手动安装MySQL5.0.16的windows service时很顺利,昨晚为5.0.83安装service时,总是提示1067的错误。网上有人说把my.ini放到C:\WINDOWS下就可以了,但我遇到的情况是问题仍然没有解决。我的解决办法是将参数中的--defaults-file用--defaults-extra-file取代,如下:

mysqld-nt--install MySQL --defaults-file=E:/mysql-5.0.83-win32/my.ini

改为

mysqld-nt--install MySQL --defaults-extra-file=E:/mysql-5.0.83-win32/my.ini

执行mysqld-nt --verbose --help能看到mysqld的用法,其中就有这两个参数的说明。

C:\Users\Administrator>mysqld-nt --verbose --help|more
mysqld-nt  Ver 5.0.96-community-nt for Win32 on ia32 (MySQL Community Edition (G
PL))
Copyright (c) 2000, 2011, 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.

Starts the MySQL database server.

Usage: mysqld-nt [OPTIONS]
NT and Win32 specific options:
--install                     Install the default service (NT)
--install-manual              Install the default service started manually (NT
)
--install service_name        Install an optional service (NT)
--install-manual service_name Install an optional service started manually (NT
)
--remove                      Remove the default service from the service list
(NT)
--remove service_name         Remove the service_name from the service list (N
T)
--enable-named-pipe           Only to be used for the default server (NT)
--standalone                  Dummy option to start as a standalone server (NT


根据我自己的实践,引起这个问题最大的可能性是数据表存储引擎(Engine,简而言之,存储引擎就是指表的类型,即Table Type

)引起的。MySQL数据库支持的数据表存储引擎有多种,可以用命令:show engines进行查看,在MySQL的配置文件my.ini中可以也看到(默认的是MyISAM):

# The default storage engine that will be used when create new tables when default-storage-engine=MyISAM。

常用的存储引擎还有InnoDB,InnoDB有多种优点,InnoDB给MySQL的表提供了事务、回滚、崩溃修复能力、多版本并发控制的事务安全.同时,InnoDB也是MySQL上第一个提供外键约束的引擎,而且InnoDB存储引擎对事务处理的能力也是MySQL其他存储引擎所无法与之比拟的。

InnoDB与MyISAM的区别:

以InnoDB存储引擎存储的表,存储表结构的.frm与存储的表数据文件(ibdata1)是分开存放的,存储表数据的文件位置可以通过修改my.ini文件自行设置:

#*** INNODB Specific options ***

innodb_data_home_dir="D:/"

以MyISAM存储引擎存储的表,一共包括3个文件:.frm(存储表的结构)文件,.MYD(MYouData的缩写,存储表的数据)文件,.MYI(MYIndex的缩写,存储表的索引),这个三个文件同时存放在MySQL数据库安装时存放数据的目录下,如F:\ProgramData\MySQL\MySQL Server 5.1\data\Databasename中。

另外,通过对这次问题的解决,我认识到了查看错误日志的重要性,当遇到问题的时候,我们首先想到的应该是去查看错误日志,而不是不加思索去Google或者去baidu,其实从错误日志中我们能得到真正造成问题的原因,对症下药,才能药到病除。MySQL的错误日志(.err)位于F:\ProgramData\MySQL\MySQL Server 5.1\data目录下,文件名一般为你的计算机名。
http://blog.sina.com.cn/s/blog_600357e40100q5ub.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: