Reprint Please specify: Look at Daniel's small fresh http://www.cnblogs.com/luruiyuan/
The main purpose of this article is to summarize the experience of death in order to find
1. Start/stop/restart of Ubuntu MySQL service:
# start Mysqlsudo service MySQL start# restart Mysqlsudo service MySQL restart# stop mysqlsudo service MySQL stop
2. No reason to fail when importing/inserting data
This is usually caused by insufficient file permissions on the Linux system, and often occurs when MySQL is first installed. This can be resolved in terminal:
3. mysql Restart/start exception:
mysql.service failed because the control process exited with error code. See "systemctl status mysql.service" and "journalctl -xe" for details.
这个错误有很多原因,通常我们有几种不同的办法来排查:
1. 根据提示,在 root 权限下输入
systemctl status mysql.service 以及
journalctl -xe 来查看日志错误信息
2. 如果上述日志不能明确指出问题,还可以在 terminal 中输入 mysql --help
对于我的这次错误而言,是我在 /etc/mysql/my.cnf 中添加了一些错误的配置,使用
mysql --help 时提示出了错误的位置(精确到了行),因此问题得以解决。
4. MySQL Linux下的配置文件及其位置
众所周知,windows下MySQL的配置文件是 my.ini, 而 Ubuntu 下的配置文件是 my.cnf。经过寻找,可以发现默认时安装在了
/etc/mysql/my.cnf 路径下
5. 导入数据时报告权限错误:
Error code 13: permission denied
这个错误目前仅出现于 Linux上,在我的 Ubuntu 上有这个错误,Windows上则从未出现:
解决办法:
通常 MySQL 5.7.6 以上版本都默认运行在指定 secure_file_priv 的情况下,因此我只说这个情况,其他类推:
在 root 权限下,找到
secure_file_priv 指定的路径,将该文件夹的权限设置为可以增删改查:
例如,我这里路径为:
/var/lib/mysql-files/
可在数据库中通过
Show variables like ' Secure_file_priv ';
来进行查看
因此在 root 权限下输入下列命令修改即可:
Chmod-r 777/var/lib/mysql-files/
6. 导入 csv 文件时出现 0 rows affected 的错误:
这个问题在我这里是由于 Windows 和 Linux 的换行符不一致导致的:
Windows 中换行符为 ‘\r\n‘,但是 Linux 中为 ‘\n‘
由于切换到 Ubuntu 不就,因此我使用了 Windows 的 ‘\r\n‘ ,结果导致数据导入时提示 0 rows affected.
SQL语句如下:
# Load Data infile ' in Windows. \\uploads\\test.csv ' into table sampletablenamefields terminated by ', ' optionally enclosed by ' ' ' escaped by ', ' Lines terminated by ' \ r \ n ' Ignore 1 lines; # Linux Load Data infile '. \\uploads\\test.csv ' into table sampletablenamefields terminated by ', ' optionally enclosed by ' ' ' escaped by ', ' Lines terminated by ' \ n ' ignore 1 lines;
mysql-Error for reference