常见问题处理
如果在服务器重启时没有正常启动我们通过脚本安装的数据库,可以使用以下命令启动:
/usr/local/mysql/bin/mysqld_safe &
如果发现数据库总是间歇性拒绝连接,可能是系统服务发生了异常,可以使用以下命令停用系统服务:
systemctl stop mysqld
systemctl disable mysqld
然后手动启动数据库:
/usr/local/mysql/bin/mysqld_safe &
如果忘记了初始密码,可以在
/usr/local/mysql/generated-password.txt
文件中找到。
如果你使用GoEdge脚本安装的MySQL并需要卸载的话,可以按照以下步骤操作:
停止服务:
systemctl stop mysqld
systemctl disable mysqld
systemctl daemon-reload
检查进程是否存在,执行:
ps ax|grep mysqld
如果出现以下内容:
12581 ? S 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe
12804 ? Sl 16:30 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=localhost.localdomain.err --pid-file=localhost.localdomain.pid --port=3306
14789 pts/1 S+ 0:00 grep --color=auto mysqld
说明
mysqld
进程仍然存在,你可以手动停止:
kill 12804
kill 12581
请将
kill
命令后的数字替换成你实际
ps
命令查询后的结果。操作后,请继续使用
ps
命令确认进程是否存在;
删除MySQL目录:
rm -rf /usr/local/mysql
删除后,确认目录是否仍然存在:
ls /usr/local/mysql
如果出现:
cannot access '/usr/local/mysql': No such file or directory
就说明删除成功了
删除
my.cnf
配置文件:
rm -f /etc/my.cnf
步骤3:初始化
先准备
mysql
用户和数据库存放目录
data/
:
cd mysql8 # 进入MySQL安装目录,以下操作都会在目录下进行
groupadd mysql
useradd mysql -g mysql
mkdir data
chown mysql:mysql data
将以前的MySQL配置文件(
/etc/my.cnf
)更名,以免影响当前新的MySQL的运行:
mv /etc/my.cnf /etc/my.cnf.bk
运行后,如果提示
mv: cannot stat ‘/etc/my.cnf’: No such file or directory
可以忽略
执行初始化:
bin/mysqld --initialize --user=mysql
将会输出类似于以下的信息:
2021-09-25T08:26:45.321239Z 0 [System] [MY-013169] [Server] /opt/mysql8/bin/mysqld (mysqld 8.0.26) initializing of server in progress as process 5964
2021-09-25T08:26:45.330015Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-09-25T08:26:45.616649Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2021-09-25T08:26:46.420358Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1 is enabled for channel mysql_main
2021-09-25T08:26:46.420949Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1.1 is enabled for channel mysql_main
2021-09-25T08:26:46.579100Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: d_qPgidGM2tl
其中
A temporary password is generated for root@localhost: d_qPgidGM2tl
中的一行的最后数据(
d_qPgidGM2tl
部分)是MySQL临时密码,每次初始化的结果都会不同,请记住这个密码。
可以使用
ls
命令查看
data/
目录下是否有内容:
ls data
正常会输出类似于以下的文件:
auto.cnf client-cert.pem #ib_16384_1.dblwr #innodb_redo/ mysql.ibd public_key.pem sys/ ...
如果没有这些文件,说明你没有把老的MySQL配置文件(
/etc/my.cnf
)更名。
导出和恢复
可以使用
mysqldump
命令导出一个数据库:
mysqldump [数据库名] -u用户名 -p > 导出的目标SQL文件
如果用户名有密码,则命令执行后,需要输入密码。
以下是一个示例:
mysqldump edges -uroot -p > /root/edges.sql
其中
edges
示例数据库名称,
root
是数据库用户名,
/root/edges.sql
是导出的目标SQL文件名。这几个参数都需要根据你自己的实际环境进行修改。
注意:如果访问日志过多,请先删除/清空访问日志再导出,功能在:”系统设置”–“手动清理”–“数据库”–“手动清理”。
可以使用
--ignore-table
来忽略某些不需要导出的表
mysqldump edges -uroot -p --ignore-table=edges.edgeHTTPAccessLogs_20220909 --ignore-table=edges.edgeHTTPAccessLogs_20220910 > /root/edges.sql
其中
edges
为数据库名。
可以使用
mysql
命令恢复一个数据库:
mysql -u用户名 -p 数据库名 < 导出的SQL文件
如果用户名有密码,则命令执行后,需要输入密码。
比如我们把
/root/edges.sql
导入
edges
数据库中:
mysql -uroot -p edges < /root/edges.sql
其中
edges
示例数据库名称,
root
是数据库用户名,
/root/edges.sql
是导出的SQL文件名。这几个参数都需要根据你自己的实际环境进行修改。