[mysql] Access denied for root user in MySQL command-line

I've just installed xampp, and am using command line to write mySQL. I am using 'root' with no password and can connect to mysql but cannot CREATE DATABASE as I get the error 1044 access denied for user '' @ 'localhost'. I am logged in as -uroot.

I have privileges in phpMyadmin to do what I want, but, in command line I seem to have no write privileges. I've looked at all the other related posts on this topic but to no avail. I cannot GRANT privileges as I have none anyway.

This question is related to mysql command-line xampp

The answer is


navigate do C:\xampp\mysql\bin\ and make sure the file mysql.exe is in that folder.

mysql -uroot -p

if dont have a password just press enter.

the prompt changes to

mysql>

do your mysql commands


You mustn't have a space character between -u and the username:

mysql -uroot -p
# or
mysql --user=root --password

Gain access to a MariaDB 10 database server

After stopping the database server, the next step is to gain access to the server through a backdoor by starting the database server and skipping networking and permission tables. This can be done by running the commands below.

sudo mysqld_safe --skip-grant-tables --skip-networking &

Reset MariaDB root Password

Now that the database server is started in safe mode, run the commands below to logon as root without password prompt. To do that, run the commands below

sudo mysql -u root

Then run the commands below to use the mysql database.

use mysql;

Finally, run the commands below to reset the root password.

update user set password=PASSWORD("new_password_here") where User='root';

Replace new_password _here with the new password you want to create for the root account, then press Enter.

After that, run the commands below to update the permissions and save your changes to disk.

flush privileges;

Exit (CTRL + D) and you’re done.

Next start MariaDB normally and test the new password you just created.

sudo systemctl stop mariadb.service
sudo systemctl start mariadb.service

Logon to the database by running the commands below.

sudo mysql -u root -p

source: https://websiteforstudents.com/reset-mariadb-root-password-ubuntu-17-04-17-10/


I had the same issue, and it turned out to be that MariaDB was set to allow only root to log in locally via the unix_socket plug-in, so clearing that setting allowed successfully logging in with the user specified on the command line, provided a correct password is entered, of course. See this answer on Ask Ubuntu


By default there is no password is set for root user in XAMPP.

You can set password for root user of MySQL.

Navigate to

localhost:80/security/index.php

and set password for root user.

Note:Please change the port number in above url if your Apache in on different port.

Open XAMPP control panel Click "Shell" button

Command prompt window will open now in that window type

mysql -u root -p;

It will ask for password type the password which you have set for root user.

There you go ur logged in as root user :D Now do what u want to do :P


Server file only change name folder

etc/mysql
rename
mysql-

Are you logging into MySQL as root? You have to explicitly grant privileges to your "regular" MySQL user account while logged in as MySQL root.

First set up a root account for your MySQL database.

In the terminal type:

mysqladmin -u root password 'password'

To log into MySQL, use this:

mysql -u root -p

To set the privileges manually start the server with the skip-grant-tables option, open mysql client and manually update the mysql.user table and/or the mysql.db tables. This can be a tedious task though so if what you need is an account with all privs I would do the following.

Start the server with the skip-grant-tables option

Start mysql client (without a username/password)

Issue the command

flush privileges;

which forces the grant tables to be loaded.

Create a new account with the GRANT command something like this (but replacing username and password with whatever you want to use.

GRANT ALL on *.* to 'username'@'localhost' identified by 'password';

Restart the server in normal mode (without skip-grant-tables) and log in with your newly created account.

Refer this MySQL docs.


this might help on Ubuntu:

go to /etc/mysql/my.cnf and comment this line:

bind-address           = 127.0.0.1

Hope this helps someone, I've been searching for this a while too

Cheers


Examples related to mysql

Implement specialization in ER diagram How to post query parameters with Axios? PHP with MySQL 8.0+ error: The server requested authentication method unknown to the client Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver' phpMyAdmin - Error > Incorrect format parameter? Authentication plugin 'caching_sha2_password' is not supported How to resolve Unable to load authentication plugin 'caching_sha2_password' issue Connection Java-MySql : Public Key Retrieval is not allowed How to grant all privileges to root user in MySQL 8.0 MySQL 8.0 - Client does not support authentication protocol requested by server; consider upgrading MySQL client

Examples related to command-line

Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools) Flutter command not found Angular - ng: command not found how to run python files in windows command prompt? How to run .NET Core console app from the command line Copy Paste in Bash on Ubuntu on Windows How to find which version of TensorFlow is installed in my system? How to install JQ on Mac by command-line? Python not working in the command line of git bash Run function in script from command line (Node JS)

Examples related to xampp

Xampp localhost/dashboard phpMyAdmin ERROR: mysqli_real_connect(): (HY000/1045): Access denied for user 'pma'@'localhost' (using password: NO) Is there way to use two PHP versions in XAMPP? Where to find htdocs in XAMPP Mac phpMyAdmin access denied for user 'root'@'localhost' (using password: NO) How to downgrade php from 7.1.1 to 5.6 in xampp 7.1.1? How to turn on/off MySQL strict mode in localhost (xampp)? mysqli_connect(): (HY000/2002): No connection could be made because the target machine actively refused it How to install mcrypt extension in xampp Fatal error: Uncaught Error: Call to undefined function mysql_connect()