Accessing MYSQL through terminal
Solution 1
To access mysql from CLI:
mysql -u <username> -p<password> <database_name>
Make sure no space between -p
and password. Of course, this password will be visible in history.
To overcome this:
- Leave it blank and it will ask you for it.
- start the command with a space in front of
mysql
Solution 2
With ...
mysql -u {user} -p {database}
The database is optional. {user} is the user you created when installing. You will get prompted for the password you supplied when installing. By the way: this is assuming you installed our native LAMP stack.
If you not yet have a user and password
mysql
will work too. If it does do make a user and password with correct privileges.
This is assuming MySQL is running.
Solution 3
Here is the official documentation about MySQL command line Tool
And a basic tutorial
Hope this helps
Solution 4
You may want to make sure the service has been started with:
sudo service mysql start
After that, if you have not set up any users or databases, then you could run:
/usr/bin/mysql -u root -p
to access the command line as root. If you set up a root password when installing LAMP then enter that. Otherwise just press enter and set the password later.
Related videos on Youtube
Parvej Islam
Updated on September 18, 2022Comments
-
Parvej Islam over 1 year
I just installed LAMP in my computer through commandline.Now how can I access MYSQL prompt from commandline?I need to use MYSQL to create tables,views and then access them from my Perl script.
-
D-unit over 8 yearsYou dont have to access MySQL from command line if you dont want to. You can use a tool like phpmyadmin, which is a tool that lets you manage your database in your browser.
-
ThunderBird about 8 yearsYou can still have to access MySQL from command line whether you want it or not. You can also use tools like phpmyadmin, mysql workbench, which let you manage your database in a GUI.
-
-
Rinzwind over 8 yearsAre you sure it is not "--password={pwd}". If seem to remember the next word after -p is considered the database. But more important: this will echo the password into the process list and if you do not want this password stored in "history" add a space in from of "mysql" ;)
-
Aizuddin Zali over 8 years-p<password> no space in between. Edited the answer.
-
Rinzwind over 8 yearsOh yes! That was it indeed. It needs to be against the -p
-
ThunderBird almost 6 yearsYou must not necessarily be root to invoke MySQL.
-
kimxons almost 6 yearsthat is true, but if the problem persists, it is always better to login as root...mine works best that way.
-
RodrikTheReader over 4 yearsWhy on earth would they require the condition that there's no space between -p and password? I spent half an hour on this believing I was a victim of some black magic.