Mysql windows connect as root

How do I log in as root in MySQL?

I’ve installed MySQL and during installation I was asked for a password which I entered, but now my teacher says that we should be able to log in as root without any password.

This works but I don’t get any privileges:

This doesn’t work:

Neither does this

1 Answer 1

Cause of the issue

The default configuration for logging in as root user in MySQL 5.7 requires use of an authentication socket. This can be verified via querying the user table:

The socket plugin checks whether the socket user name (the operating system user name) matches the MySQL user name specified by the client program to the server. If the names do not match, the plugin checks whether the socket user name matches the name specified in the authentication_string column of the mysql.user system table row. If a match is found, the plugin permits the connection.

In other words, mysql by default doesn’t have root password set — you need to either run phpMyAdmin as root or via sudo (both of which are bad idea for security reasons), or you change the authentication method and reset the root password as shown in Digital Ocean tutorial.

Note that aside from same name, MySQL users and system users are not the same. You can have a MySQL user jdoe and have no such user on the host system. Thus, root is MySQL’s root user, not system user.

Steps to change plugin and password:

open terminal and run sudo mysql -u root . You should see a greeting message and mysql> prompt. This is the MySQL shell, which is different from your command-line shell, so only SQL statements are accepted here.

Enter the following sequence of SQL queries:

Exit and attempt to sign in:

If everything goes well, you should be able to sign in from phpMyAdmin via the new password. If something goes wrong, attempt to restart the server without permission checking (that’s step num. 3 in the Digital Ocean tutorial). For other issues, feel free to ask another question here or on Database Administrators — Stack Exchange

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.

9 Answers 9

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.

Читайте также:  Adobe illustrator linux 2011

First set up a root account for your MySQL database.

In the terminal type:

To log into MySQL, use this:

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

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.

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

How to connect from windows command prompt to mysql command line

I’m trying to connect to mysql server command line from my windows prompt

I write the next line in cmd but i get an error.

And then i execute

but i getting this error

17 Answers 17

The cd in your question is invalid (quoting it here because you’ve removed it once, and it was there when this answer was posted):

You can’t cd to CD:\ anything, because CD:\ isn’t a valid directory in Windows. CD: would indicate a drive, except that drives are restricted to a single letter between A and Z .

If your \MYSQL\BIN is on drive C: , then your commands need to be:

If you’re not already on C: (which you’ll know by looking at the prompt in the cmd window), or your MySQL folder is on another drive (for instance, D: ), change to that drive too:

The .exe after mysql is optional, since .exe is an executable extension on Windows. If you type mysql , Windows will automatically look for an executable file with that name and run it if it finds it.

Note that in both my examples of running mysql , there are no = signs. You should just use -p with no password, and wait to be prompted for it instead.

then type password

C:\Program Files\MySQL\MySQL Server 5.7\bin> mysql -u username -p

Then it will ask for the password. Enter the password you set for the username during installation while adding db Users.

first type cmd then the windows command prompt will appear:

  • -u is the user id
  • -p is the password, if you will not using a password just leave it blank.

You are logging in incorrectly; you should not include = in your login. So to log in, type:

If that doesn’t work, then you may not have your system configured. If so, then here’s a good tutorial on getting started with the MySQL prompt: http://breakdesign.blogspot.com/2007/11/getting-started-with-php-and-mysql-in_11.html

  1. Start your MySQL server service from MySQL home directory. Your one is C:\MYSQL\bin\ so choose this directory in command line and type: NET START MySQL
    (After that you can open Windows Task Manager and verify in Processes tab is mysqld.exe process running. Maybe your problem is here.)
  2. Type: mysql -uuser-p [pressEnter]
  3. Type your password [pressEnter]
Читайте также:  Rufus windows iso usb

or make a start.bat file:

  1. add C:\MYSQL\bin\ to your PATH
  2. write a start.bat file My start.bat file has only two lines like below:
    net start MySQL
    mysql -u root -p

Simply to login mysql in windows , if you know your username and password.

Open your command prompt, for me the username is root and password is password

Hope it would help many one.

Please perform the following steps

    First, open your command prompt with Administrator.

Go to MySQL installed directory and copy path and past on command prompt like:- C:\Program Files\MySQL\MySQL Server 5.7\bin>

C:\Program Files\MySQL\MySQL Server 5.7\bin>mysql -uroot -p [-u for username -p for password]

C:\Program Files\MySQL\MySQL Server 5.7\bin>mysql -uroot -p Enter password: **** [enter your password here]

I have used following command to connect MySQL Server 8.0 in Windows command prompt.

or

Here my_db is schema name.

Following commands will connect to any MySQL database

Since it shows the password in plain text, you can type password later as prompted. So, the command will be as follows

Your have to go on mysql installed path is on drive C:, then your commands need to be:

That will ask your MySql password over command prompt:

Put the password and you will get mysql dashboard.

Go to your MySQL directory. As in my case its.

root can be changed to your user whatever MySQL user you’ve set.

It will ask for your password. If you have a password, Type your password and press «Enter», If no password set just press Enter without typing. You will be connected to MySQL.

There is another way to directly connect to MySQL without every time, going to the directory and typing down the commands.

Create a .bat file. First, add your path to MySQL. In my case it was,

Then add these two lines

If you don’t want to type password every time you can simply add password with -p e.g. -proot (in case root was the password) but that is not recommended.

Also, If you want to connect to other host than local (staging/production server). You can also add -h22.345.80.09 E.g. 22.345.80.09 is your server ip.

Save the file. Just double click to open and connect directly to MySQL.

First jump to the mysql bin directory. You have two ways to connect

1) mysql -u root -p1234 (without space for password flag) 2) mysql -u root -p and enter the password when it is asking

To make it easier to invoke MySQL programs, you can add the path name of the MySQL bin directory to your Windows system PATH environment variable:

On the Windows desktop, right-click the My Computer icon, and select Properties.

Next select the Advanced tab from the System Properties menu that appears, and click the Environment Variables button.

Under System Variables, select Path, and then click the Edit button. The Edit System Variable dialogue should appear.

Place your cursor at the end of the text appearing in the space marked Variable Value. (Use the End key to ensure that your cursor is positioned at the very end of the text in this space.) Then enter the complete path name of your MySQL bin directory (for example, C:\Program Files\MySQL\MySQL Server 8.0\bin ).

Читайте также:  Kyocera fs 4100dn драйвер windows 10

Open a different terminal and if you are using root as user run mysql -u root -p else use the a different username you created.

Login to MySQL server from command line

In Windows, MySQL, by default, is installed in the folder %systemdrive%\Program Files\MySQL. For example, if the system drive is C:, then the installation directory for MySQL server 5.5 would be C:\Program Files\MySQL\MySQL Server 5.5\

We can connect to MySQL server by running the mysql.exe located in the bin folder in the mysql installation directory.

If you just run mysql without passing any arguments, you can connect to the server with anonymous account. This works only if the anonymous account is not disabled. When you install MySQL, by default, it enables anonymous access.

Connect to MySQL as root

You can connect to MySQL server by specifying the user name and password in the command line arguments to mysql command. To connect as root, the command would be as below.

You will be prompted for password if -p option is skipped. If MySQL service is not running then the command would fail with the below error

You can create a desktop batch file to launch MySQL client as follows.

  • Create a text file and name it as mysql.bat.
  • Add the following command to the mysql.bat file.
  • cmd /K “C:\Program Files\MySQL\MySQL Server 5.5\bin\mysql.exe” -uroot -ppassword
  • Change the mysql.exe path as per your MySQL server version and install directory.
  • Save the file. Now onwards you can connect to server by just double clicking on the batch file.

Alternative way is to create a desktop shortcut with the target as C:\Program Files\MySQL\MySQL Server 5.5\bin\mysql.exe. After creating the shortcut, open the properties and add -uroot -ppassword to the target field.

The default installation of MySQL creates a shortcut in Start menu-> All Programs with the target as below. You can use it as the target for your desktop shortcut.

Как включить доступ root к MySQL и MariaDB с любых хостов

Для того чтобы пользователь root (или любой другой пользователь) мог подключиться с СУБД MySQL с удалённого хоста, необходимо выполнение двух условий:

1) в свойствах пользователя должно быть разрешено подключаться с удалённых хостов

2) СУБД должна прослушивать входящие соединения не только с localhost/127.0.0.1, но и на интерфейсах с внешними IP адресами.

В этой инструкции мы включим доступ root к MySQL и MariaDB с удалённых хостов.

Этот процесс состоит из двух этапов:

а) Настройка привилегии. Выполните как пользователь root, заменив ‘ПАРОЛЬ’ текущим паролем root:

б) Разрешить MySQL прослушивать все сетевых интерфейсы для возможности подключения с внешних IP:

Самый простой способ — закомментировать строку в файле my.cnf, чтобы получилось так:

Файл mysql.cnf может быть расположен по следующим путям:

  • /etc/mysql/conf.d/mysql.cnf
  • /etc/mysql/mariadb.cnf
  • /etc/mysql/mysql.conf.d/mysqld.cnf

Чтобы изменения вступили в силу, перезапустите службу mysql:

По умолчанию прослушивается только соединения с localhost, но если вы закомментируете строку, MySQL откроет порты для входящих соединений на всех интерфейсах. Комментирование строки эквивалентно bind-address=*.

Чтобы проверить, какие порты прослушивает служба mysql:

Оцените статью