Link to home
Create AccountLog in
Avatar of neal wang
neal wang

asked on

How can I login as root for mysql8?

I'm on centos7, mysql8

Mysocial engine complaining that it can't login to the mysql database using the root login

I'm trying to login
# mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

I of course went through the mysql8 documentation

I also asked this question before but I tried the steps and it didn't work, I think it fails upon restarting my machine... how do I get a permanent solution to this? is what helped me last time.. but it is not working
Avatar of David Favor
David Favor
Flag of United States of America image

This means the password you input for the root user is incorrect.

Normally CentOS package installation saves the root user/pass into the ~root/.my.cnf file for future use.

So you must prepend all your mysql commands with a pointer to this file, as in...

mysql --defaults-extra-file=~root/.my.cnf ...

Open in new window

As with all root level commands + permissions, you must be root to use a root level login.

If this fails, you can run with --skip-grants or reset the root password.

Careful: If you reset the root password + some other code has cached the root password, then database related code may become unstable.
If you must reset the root password provides details showing how to reset the root password for MariaDB + MySQL.
Avatar of neal wang
neal wang


[1] 72942
[# -bash: mysqld_safe: command not found

[1]+  Exit 127                mysqld_safe --skip-grant-tables
the worst thing is, I'm on the documentation page.. the command should be working
First start at the beginning.

State whether the file ~root/.my.cnf exists or is missing.
yes it exists,

its located


# For advice on how to change settings please see

# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove the leading "# " to disable binary logging
# Binary logging captures changes between backups and is enabled by
# default. It's default setting is log_bin=binlog
# disable_log_bin
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
# Remove leading # to revert to previous value for default_authentication_plugin,
# this will increase compatibility with older clients. For background, see:
default_authentication_plugin= mysql_native_password


I rebooted my system and now, I'm not able to start up mysql service

 systemctl start mysqld
Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.
[root@dxpdemo ~]# systemctl status mysqld.service
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Fri 2020-01-24 14:44:16 UTC; 9s ago
     Docs: man:mysqld(8)
  Process: 5562 ExecStart=/usr/sbin/mysqld $MYSQLD_OPTS (code=exited, status=1/FAILURE)
  Process: 5533 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 5562 (code=exited, status=1/FAILURE)
   Status: "Server startup in progress"
    Error: 13 (Permission denied)

Jan 24 14:44:15 dxpdemo systemd[1]: Starting MySQL Server...
Jan 24 14:44:16 dxpdemo systemd[1]: mysqld.service: main process exited, code=exited, status=1/FAILURE
Jan 24 14:44:16 dxpdemo systemd[1]: Failed to start MySQL Server.
Jan 24 14:44:16 dxpdemo systemd[1]: Unit mysqld.service entered failed state.
Jan 24 14:44:16 dxpdemo systemd[1]: mysqld.service failed.
should I just reinstall mysql at this point
Avatar of neal wang
neal wang

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account