1. 开启数据库
bash
mysql
开启数据库时提示错误 ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
查找sock文件
bash
find / -name '*.sock'
将该sock文件设置软连接到提示错误的位置
bash
ln -s /run/mysqld/mysqld.sock /tmp/mysql.sock
2.删除数据库
python
drop database test_database;
3.卸载数据库后再安装找不到文件
先执行命令
bash
apt-get remove --purge mysql-*
再正常安装
bash
apt -y install mariadb-server
systemctl restart mariadb
4.连接数据库时指定hostname为127.0.0.1,访问失败
bash
mysql -u root -p -h 127.0.0.1
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
但直接"mysql"可以访问,执行如下命令:
bash
use mysql
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
flush privileges;
exit
然后可以通过"mysql -u root -p -h 127.0.0.1"登录
5.向数据库导入csv数据
bash
use electricity
LOAD DATA INFILE '/tmp/power_plot.csv' INTO TABLE plot FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' IGNORE 1 ROWS;
# '/tmp/power_plot.csv'为文件名,plot为数据库表名;csv文件以逗号分隔,以'\n'换行,忽略第一行的列头。
# 文件放在/tmp文件夹下,数据库默认读取该路径,否则会报错。