1.导入数据命令:
mysql --host=localhost --port=3306 --user=root --password=hnsjt_lwsj@2018 szyszx_20180515-114403<D:lwsjshengcaizhengting预算执行标准表_mysqlszyszx_20180515-114403_full.sql
2.授权:
mysql -uroot -p 登录 grant select on lwsj_huanbao.* to root@'%' grant create on lwsj_huanbao.* to root@'%' grant alter on lwsj_huanbao.* to root@'%' grant trigger on lwsj_huanbao.* to root@'%' grant insert on lwsj_huanbao.* to root@'%' grant update on lwsj_huanbao.* to root@'%' grant delete on lwsj_huanbao.* to root@'%' grant drop on lwsj_huanbao.* to root@'%' grant index on lwsj_huanbao.* to root@'%'
--同时授权多个权限 grant select,create,alter,trigger,insert,update,delete,drop,index on lwsj_lvyou.* to root@'%'; ,加好后,再show grants for root;
3.远程连接授权
bat脚本:
@ECHO OFF SET dbhost=127.0.0.1 SET dbuser=root SET dbpasswd=hnsjt_lwsj@2018 SET dbName=test SET sqlpath=%~dp0 set sqlfile=C:/Program Files/MySQL/MySQL Server 5.5/bin/update.sql mysql -h%dbhost% -u%dbuser% < update.sql --default-character-set=utf8 ECHO 完成! PAUSE
update.sql
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'hnsjt_lwsj@2018' WITH GRANT OPTION; FLUSH PRIVILEGES; set password for root@127.0.0.1 = password('hnsjt_lwsj@2018'); set password for root@localhost = password('hnsjt_lwsj@2018');
4.设置连接等待和文本长度限制(mysql has gone)
(1)通过命令行设置:
原因一. MySQL 服务宕了
判断是否属于这个原因的方法很简单,进入mysql控制台,查看mysql的运行时长
mysql> show global status like 'uptime';
+---------------+---------+
| Variable_name | Value |
+---------------+---------+
| Uptime | 3414707 |
+---------------+---------+
1 row in set或者查看MySQL的报错日志,看看有没有重启的信息
如果uptime数值很大,表明mysql服务运行了很久了。说明最近服务没有重启过。
如果日志没有相关信息,也表名mysql服务最近没有重启过,可以继续检查下面几项内容。
原因二. mysql连接超时
即某个mysql长连接很久没有新的请求发起,达到了server端的timeout,被server强行关闭。
此后再通过这个connection发起查询的时候,就会报错server has gone away
(大部分PHP脚本就是属于此类)
mysql> show global variables like '%timeout';
+----------------------------+----------+
| Variable_name | Value |
+----------------------------+----------+
| connect_timeout | 10 |
| delayed_insert_timeout | 300 |
| innodb_lock_wait_timeout | 50 |
| innodb_rollback_on_timeout | OFF |
| interactive_timeout | 28800 |
| lock_wait_timeout | 31536000 |
| net_read_timeout | 30 |
| net_write_timeout | 60 |
| slave_net_timeout | 3600 |
| wait_timeout | 28800 |
+----------------------------+----------+
10 rows in set
wait_timeout 是28800秒,即mysql链接在无操作28800秒后被自动关闭
原因三. mysql请求链接进程被主动kill
这种情况和原因二相似,只是一个是人为一个是MYSQL自己的动作
mysql> show global status like 'com_kill';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| Com_kill | 21 |
+---------------+-------+
1 row in set原因四. Your SQL statement was too large.
当查询的结果集超过 max_allowed_packet 也会出现这样的报错。定位方法是打出相关报错的语句。
用select * into outfile 的方式导出到文件,查看文件大小是否超过 max_allowed_packet ,如果超过则需要调整参数,或者优化语句。
mysql> show global variables like 'max_allowed_packet';
+--------------------+---------+
| Variable_name | Value |
+--------------------+---------+
| max_allowed_packet | 1048576 |
+--------------------+---------+
1 row in set (0.00 sec)
修改参数:
mysql> set global max_allowed_packet=1024*1024*16;
mysql> show global variables like 'max_allowed_packet';
+--------------------+----------+
| Variable_name | Value |
+--------------------+----------+
| max_allowed_packet | 16777216 |
+--------------------+----------+
1 row in set (0.00 sec)
(2)通过修改my.ini设置:
在my.cnf文件中添加或者修改以下两个变量:
wait_timeout=2880000
interactive_timeout = 2880000
在my.cnf文件中添加或者修改以下变量:
max_allowed_packet = 10M(也可以设置自己需要的大小)
max_allowed_packet 参数的作用是,用来控制其通信缓冲区的最大长度。