I am trying to connect to MySQL database from MySQL shell on windows.
No matter what I type in MySQL shell, it keeps giving me error : 'Not connected'.
Query eg 1 : mysql --host=localhost --port=3306 --user=root -p;
Query eg 2 : mysql -u root -p
O/P : ERROR: Not connected
I have MySQL server installed on my machine. Also MySQL service is running in the background.
Also, I was able to connect from MySQL workbench.
ERROR MESSAGE
MySQL Workbench Connection
My temporary workaround is that I make use of ssl protocol to connect to MySQL server :
MySQL> \connect root#localhost
MySQL localhost:33060+ ssl SQL > show databases;
The first step is that you need to check if you are in the MYSQL Shell SQL mode or JS mode.
Then if you are in SQL mode then you are good to go else you need to switch to SQL mode by this command
\sql
The next step is to connect using this command
\connect root#localhost
In your case, you might have given the privilege as the IP address so you need to check your localhost IP which can be done by this command in your command prompt.
ipconfig and then just check the IP address and put it in place of localhost in the previous command. If this still doesn't works then put 127.0.0.1:3306.
After this, it will prompt to add or save the password , enter a unique password there.
After this you are good to go and check the user and localhost after this by this command
SELECT user, host FROM mysql.user;
Try mysql -u root -p
I haven't used MySQL shell, I typically use gitbash and it works just fine
I had faced the same issue on my Windows 10 machine with MySQL 5.7 and the following commands helped me:
mysqlsh.exe - to open mysql shell; then
\sql - to start working with SQL;
finally:
\connect root#127.0.0.1:3306
You can use:
mysql -uroot -hlocalhost -P3306 -p
or
mysql -uroot -h127.0.0.1 -P3306 -p
or
mysql -uroot -p
Related
I am connecting to database mysql using command prompt using below command
mysql -h localhost -u test -ptest test;
But i am getting following error:-
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'mysql
-h localhost -u test -ptest test' at line 1
I have done a lot of googling but could not find the reason behind this problem. Any help?
It seems you are executing the statement at mysql command line console but not at system shell prompt.
The statement
mysql -h localhost -u test -ptest test;
is for system shell prompt.
And while running at command prompt, you don't need to terminate the command by a semi colon.
And for suppressing use of password at command line,
change
-ptest
to
-p
It then prompts you to input your password.
You need to run that command (which starts the mysql shell) from the command prompt.
You are trying to run it inside the mysql shell.
First make sure your command line doesnt show
mysql>
prefix. if it shows you are already in the mysql console.
you have to type the command outside the mysql console.
mysql -h localhost -u test -ptest
That will fix you issue.
Refer Mysql documentation for more information
http://dev.mysql.com/doc/refman/5.0/en/connecting.html
Thanks.
mysql -u root -p -h localhost
then command would ask for password, input it and you can logged into mysql server
I'm using MySQL 5.0 and I created a new user in my database:
create user 'johann'#'localhost' identified by 'johann22';
grant select on jewellery.customers to 'johann'#'localhost';
Now I'd like to connect as that new user but every time a quit MySQL, the command directly prompt me the password of 'root'
I have already tried to connect with root then connect to as the new user using this code:
-u johann -p johann22;
but it says that I have a syntax error.
-u johann -p johann22; is not an SQL command you can run in the mysql client. Those are command-line options for the mysql client.
So you would run this in your shell (not in the mysql client):
mysql -u johann -pjohann22
Also notice that you must NOT have a space between -p and the password. If you have a space, the -p means to prompt you for a password, then the word following the space (johann22) is the name of the database.
Abhimanyus-MacBook-Pro:~ abhimanyuaryan$ /usr/local/zend/mysql/bin/mysql -u root
ERROR 2002 (HY000): Can't connect to local MySQL server through
socket '/usr/local/zend/mysql/tmp/mysql.sock' (2)
I was trying to use MySQL database via terminal using the above command but then this error message showed up. How to fix it?
try bellow command
mysql -u root -h localhost -p
and give the root password
or you can install phpmyadmin and use it directly form the http://localhost/phpmyadmin after installing phpmyadmin.
This is not a issue, just a curiosity which I couldn't find any answer for on mysql's reference or googling:
First of all I know that to connect to a database I would run on bash:
mysql -h myhost -u myusername -p
But if I just run the mysql command without parameters I have the mysql> prompt and on the help I can see that there's a 'connect' command. But you can't set the user or password, just the database and host so it will always deny the access naturally.
I also tried to run mysql with just the username and password parameters from bash (to specify the db and host later) but that don't work either. So, does the connect command work only if you ran mysql with the username and pass which are the same for another host? Or does it have more uses?
This is not secured but you can set mysql password on Unix shell as:
export MYSQL_PWD=secret
# then run mysql client to connect
mysql
mysql> connect somedb localhost
mysql> show tables
See MySQL Manual for list of environment variables
PS: mysql will use your unix user as mysql user for connecting. Alternatively you can set env variable USER on Windows or NetWare.
Apparently, I cannot connect to SQL server using the mysql.exe
I logged in as the root user and typed the following
mysql -u root -p
mysql> CONNECT TO 127.0.0.1:3306;
I receive the folling error.
ERROR 2005 (HY000): Unknown MySQL server host '127.0.01:3306' (2)
Unknown MySQL server host '127.0.0.1:3306' (2)
However it connects justs fine using MySQL Workbench with the same parameters.
Host:127.0.0.1
Port:3306
User: root
pass:[empty]
I have the easyphp MySQL module installed. Could this be the reason?
EDIT: TYPO with 127.0.0.1 sorry
According to the documentation, the syntax of the connect command is:
connect [db_name host_name]], \r [db_name host_name]]
Reconnect to the server. The optional database name and host name arguments may be given to specify the default database or the host where the server is running. If omitted, the current values are used.
Therefore your command CONNECT TO 127.0.0.1:3306 is attempting to connect to a database called TO on a host called 127.0.0.1:3306. The error message you receive in return unsurprisingly complains that the host does not exist.
However, it is more usual to specify the hostname and database on invoking mysql (whereupon one can also specify the port if one wishes - see this page for a full list of command line options):
mysql -u username -p -h <hostname> -P <port> db_name
Also note that if the hostname and port are not specified, they default to localhost and 3309 - therefore in your case you can omit all of the above and just go with:
mysql -u username -p db_name
To do what you're currently doing (not specifying the database name on the command-line), you must call the USE command at the mysql> prompt to select a database after you've connected:
mysql -u username -p
mysql> USE db_name;
127.0.01 is explicitly misspelled. 127.0.0.1 is correct
127.0.01:3306 IS NOT 127.0.0.1:3306
You forgot the dot.