Accessing MYSQL through terminal
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.
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.