尝试初始化不安全的mysql后,一个新的安装在ubuntu WSL

qoefvg9y  于 12个月前  发布在  Mysql
关注(0)|答案(1)|浏览(226)

我想初始化不安全的mysql,但即使是全新安装也不起作用:

mysqld --initialize-insecure
mysqld: Can't create directory '/var/lib/mysql/' (OS errno 17 - File exists)
2023-05-22T17:35:25.059166Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.33-0ubuntu0.20.04.2) initializing of server in progress as process 8886
2023-05-22T17:35:25.059914Z 0 [ERROR] [MY-010187] [Server] Could not open file '/var/log/mysql/error.log' for error logging: Permission denied
2023-05-22T17:35:25.059949Z 0 [ERROR] [MY-013236] [Server] The designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it.
2023-05-22T17:35:25.059954Z 0 [ERROR] [MY-010119] [Server] Aborting
2023-05-22T17:35:25.060000Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.33-0ubuntu0.20.04.2)  (Ubuntu).

我尝试将日志设置为mysql:mysql,并使用空的/var/lib/mysql/,但似乎不起作用我应该怎么做才能使初始化不安全?
编辑:
多亏了Zak,我现在可以运行命令了(我把文件夹权限改为我的用户而不是mysql)

[Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.

不过:

mysql -u root
ERROR 1698 (28000): Access denied for user 'root'@'localhost'

据我所知,根应该在这里工作。
PS:这是一个开发站,它不是生产

j5fpnvbx

j5fpnvbx1#

现在您已经在这里并且可以尝试登录。但是root是空的,所以它总是失败。您需要执行以下步骤来“保护”您的设置。
我只回答这个问题,因为它是一个开发机器。我绝不建议在存储了敏感数据的生产机器上跳过grant。

**注意:**本例中使用vim..但是你可以使用NANO或者任何你觉得舒服的编辑器。关键是将skip-grant-tables添加到my.cnf文件的末尾--这使得MySQL几乎不需要登录就可以运行,从而允许我们更改root的密码。然后,在更改密码后从my.cnf中删除skip-grant-tables,并重新启动mysql以要求提供有效凭据。

要查找配置文件的位置,您可以运行mysqladmin --help--这应该会给予您类似于以下内容:

$ mysqladmin --help
...
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf ~/.my.cnf
...

如果打开文件并看到类似以下内容:

!includedir /etc/mysql/conf.d/
 !includedir /etc/mysql/mysql.conf.d/

这些是实际配置文件的位置。它只是包括这些目录中的所有文件。只需选择最后一个文件,并把跳过赠款在该文件的末尾。
您现在可以开始了。

$ sudo su
$ vi /etc/my.cnf

skip-grant-tables添加到文件的末尾。保存并退出。

$ service mysql restart
$ service mysql status
mysql.service - MySQL Community Server
    Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
    Active: active (running) since Fri 2022-08-12 18:45:46 CDT; 9 months 8 days ago
    Main PID: 970 (mysqld)
    Status: "Server is operational"
    Tasks: 45 (limit: 19110)
    Memory: 878.3M
    CGroup: /system.slice/mysql.service
         └─970 /usr/sbin/mysqld

$ mysql
Login Message
mysql> use mysql;
mysql> UPDATE user SET `authentication_string` = PASSWORD('ABC123') WHERE `User` = 'root'; 
mysql> exit
Bye
$ vi /etc/my.cnf

删除行--> skip-grant-tables保存并退出。

$ service mysqld restart
$ service mysql status
mysql.service - MySQL Community Server
    Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
    Active: active (running) since Fri 2022-08-12 18:45:46 CDT; 9 months 8 days ago
    Main PID: 970 (mysqld)
    Status: "Server is operational"
    Tasks: 45 (limit: 19110)
    Memory: 878.3M
    CGroup: /system.slice/mysql.service
         └─970 /usr/sbin/mysqld
$ exit
$ mysql -u root -p

相关问题