service mysql start * Starting MySQL database server mysqld No directory, logging in with HOME=

本文介绍了一种在Ubuntu 16环境下安装MySQL后遇到的启动错误,并提供了详细的解决步骤,包括停止MySQL服务、更改MySQL用户的家目录等操作。

在ubuntu 16的版本中,安装了mysql 后,启动时,程序提示  Starting MySQL database server mysqld    No directory, logging in with HOME=的错误。

解决办法:

  1. Stop MYSQL service:

    sudo service mysql stop

  2. Change home directory of mysql from nonexistent to original directory where it is supposed to be:

    sudo usermod -d /var/lib/mysql/ mysql

    3. Now start mysql server again with:

        sudo service mysql start


Beginning configuration step: Writing configuration file Saving my.ini configuration file... Saved my.ini configuration file. Ended configuration step: Writing configuration file Beginning configuration step: Updating Windows Firewall rules Adding a Windows Firewall rule for MySQL57 on port 3306. Attempting to add a Windows Firewall rule with command: netsh.exe advfirewall firewall add rule name="Port 3306" protocol=TCP localport=3306 dir=in action=allow 纭畾銆? Successfully added the Windows Firewall rule. Ended configuration step: Updating Windows Firewall rules Beginning configuration step: Adjusting Windows service Attempting to grant the required filesystem permissions to the 'NT AUTHORITY\NetworkService' account. Granted permissions to the data directory. Adding new service New service added Ended configuration step: Adjusting Windows service Beginning configuration step: Initializing database (may take a long time) Deleting the data directory from a previous (failed) configuration... Attempting to run MySQL Server with --initialize-insecure option... Starting process for MySQL Server 5.7.44... Starting process with command: F:\mysql\m\bin\mysqld.exe --defaults-file="F:\mysql\y\my.ini" --console --initialize-insecure=on --lower-case-table-names=1... TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). InnoDB: New log files created, LSN=45790 InnoDB: Creating foreign key constraint system tables. mysqld: File '.\姹熷鐪?slow.log' not found (Errcode: 2 - No such file or directory) Could not use 姹熷鐪?slow.log for logging (error 2 - No such file or directory). Turning logging off for the server process. To turn it on again: fix the cause, then either restart the query logging by using "SET GLOBAL SLOW_QUERY_LOG=ON" or restart the MySQL server. No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 42751b4d-8dec-11f0-b5f1-025034608cb2. Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher. A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher. CA certificate ca.pem is self signed. root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option. Process for mysqld, with ID 19428, was run successfully and exited with code 0. Successfully started process for MySQL Server 5.7.44. MySQL Server 5.7.44 intialized the database successfully. Ended configuration step: Initializing database (may take a long time) Beginning configuration step: Updating permissions for the data folder and related server files Attempting to update the permissions for the data folder and related server files... Inherited permissions have been converted to explicit permissions. Full control permissions granted to: NETWORK SERVICE. Full control permissions granted to: Administrators. Full control permissions granted to: CREATOR OWNER. Full control permissions granted to: SYSTEM. Access to the data directory is removed for the users group. Permissions for the data folder and related server files are updated correctly. Ended configuration step: Updating permissions for the data folder and related server files Beginning configuration step: Starting the server Attempting to start service MySQL57.................... 只有在任务处于完成状态(RanToCompletion、Faulted 或 Canceled)时才能释放它。 Ended configuration step: Starting the server . Found existing data directory, no need to initialize the database. Found existing data directory, no need to initialize the database.帮我解决
最新发布
09-11
当你在 Docker 容器中尝试启动 MySQL 服务时,遇到了错误 `su: warning: cannot change directory to /nonexistent: No such file or directory`。这个错误通常是因为容器内的用户配置问题或目录权限问题。 以下是解决问题的详细步骤和代码示例。 --- ### 解决方案:解决 MySQL 服务无法启动的问题 #### 方法 1: 检查 MySQL 用户的家目录 1. **进入容器并检查 MySQL 用户**: 使用以下命令进入容器: ```bash docker exec -it some-mysql bash ``` 然后检查 MySQL 用户的家目录是否正确: ```bash grep mysql /etc/passwd ``` 输出可能类似于以下内容: ``` mysql:x:999:999:MySQL Server:/nonexistent:/bin/false ``` 2. **修复家目录路径**: 如果家目录路径为 `/nonexistent`,可以将其修改为正确的路径(例如 `/var/lib/mysql`)。 ```bash usermod -d /var/lib/mysql mysql ``` 3. **验证更改**: 再次检查 MySQL 用户的家目录: ```bash grep mysql /etc/passwd ``` 输出应显示为: ``` mysql:x:999:999:MySQL Server:/var/lib/mysql:/bin/false ``` --- #### 方法 2: 检查数据目录权限 1. **确保数据目录存在**: 检查 `/var/lib/mysql` 目录是否存在: ```bash ls -ld /var/lib/mysql ``` 如果目录不存在,可以手动创建它: ```bash mkdir -p /var/lib/mysql ``` 2. **设置正确的权限**: 将数据目录的所有权设置为 `mysql:mysql`: ```bash chown -R mysql:mysql /var/lib/mysql ``` 3. **初始化数据目录(如果需要)**: 如果数据目录为空,可以使用以下命令初始化: ```bash mysqld --initialize --user=mysql --datadir=/var/lib/mysql ``` --- #### 方法 3: 手动启动 MySQL 服务 如果上述步骤完成后仍然无法通过 `service mysql start` 启动服务,可以尝试直接运行 MySQL 进程。 1. **启动 MySQL 进程**: ```bash mysqld --user=mysql & ``` 2. **验证服务状态**: 检查 MySQL 是否正在运行: ```bash ps aux | grep mysqld ``` --- #### 方法 4: 检查容器日志 如果问题仍未解决,可以通过查看容器日志来进一步排查。 1. **查看容器日志**: ```bash docker logs some-mysql ``` 日志中可能会显示更多关于启动失败的详细信息。 2. **常见问题及解决方法**: - **配置文件错误**:检查 `/etc/mysql/my.cnf` 文件是否有语法错误。 - **端口冲突**:确保没有其他进程占用 MySQL 的默认端口 `3306`。 --- ### 示例代码:验证 MySQL 是否正常工作 以下是一个使用 Python 和 `pymysql` 库连接 MySQL 并执行简单查询的示例代码: ```python import pymysql try: # 建立连接 connection = pymysql.connect( host='127.0.0.1', # 主机地址 user='root', # 用户名 password='my-secret-pw', # 密码 port=3306 # 端口号 ) print("Connection successful!") # 创建游标对象 cursor = connection.cursor() # 执行查询 cursor.execute("SHOW VARIABLES LIKE 'basedir';") result = cursor.fetchone() print(f"MySQL Base Directory: {result}") except pymysql.MySQLError as e: print(f"Error: {e}") finally: # 关闭连接 if connection: connection.close() ``` #### 解释: - **连接 MySQL**:通过 `pymysql.connect` 函数连接到 MySQL。 - **查询变量**:使用 `SHOW VARIABLES` 查看 MySQL 的安装路径。 - **异常处理**:捕获并打印连接错误信息。 --- ### 解释 1. **错误原因**:`su: warning: cannot change directory to /nonexistent` 表示 MySQL 用户的家目录被设置为无效路径 `/nonexistent`,这可能导致服务无法正常启动。 2. **解决方法**:通过修复用户家目录、检查数据目录权限以及手动启动 MySQL 进程,可以解决该问题。 3. **验证连接**:使用 Python 脚本验证 MySQL 是否正常工作。 --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值