Welcome to WebmasterWorld Guest from 54.146.201.80

Forum Moderators: bakedjake

Message Too Old, No Replies

How to access mysql from ssh?

     
4:30 pm on Aug 23, 2006 (gmt 0)

Full Member

10+ Year Member

joined:Aug 16, 2005
posts:240
votes: 0


Hi, I use godaddy's virtual dedicated servers and have SSH access, but they won't tell me what the command is for accessing mysql. Simply typing in "mysql" at the command line yields a 1045 error. Can anyone tell me how I can figure this out?

Thanks!

4:45 pm on Aug 23, 2006 (gmt 0)

Administrator

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 31, 2003
posts:12533
votes: 0


That is an "Access denied for user '%s'@'%s' (using password: %s)" message. When you invoke the command line interface (CLI) you need to specify at least the user and password, but often times the host and database as well. Try
mysql -u username -p databasename

You will be prompted for your password as that is what the
-p
switch is for. You could actually type in your password directly after the switch, but that is bad practice as it is entered into the bash logs where anybody with access to the logs will find your open text password.

More info on the MySQL command line options:
[dev.mysql.com...]

4:46 pm on Aug 23, 2006 (gmt 0)

Preferred Member

10+ Year Member

joined:Oct 1, 2004
posts:607
votes: 0


Something along the lines of:

mysql -h hostname -u user -ppassword databasename

see e.g. [dev.mysql.com...]

8:23 pm on Aug 23, 2006 (gmt 0)

Full Member

10+ Year Member

joined:Aug 16, 2005
posts:240
votes: 0


I see. That worked. Now, that works if you're administering an existing database, but lets say that you don't have any databases on your server or that you want to create a new one. Would that be a ssh command?

Just so you know where I'm coming from, I have plesk installed on this server and so far, I've set up all my databases in plesk.

Thanks again.

8:30 pm on Aug 23, 2006 (gmt 0)

Preferred Member

10+ Year Member

joined:Oct 1, 2004
posts:607
votes: 0


You need to connect to MySQL as the root user (the MySQL root user, not the Linux root user) and simply "CREATE DATABASE nameofnewdatabase".
8:37 pm on Aug 23, 2006 (gmt 0)

Full Member

10+ Year Member

joined:Aug 16, 2005
posts:240
votes: 0


Oh I think I was logging in as an individual database user. Is there a way for me to figure out what the root login for mysql is through SSH? Or would I have to ask my web host? They're not very good at helping with this type of stuff.
9:19 pm on Aug 23, 2006 (gmt 0)

Preferred Member

10+ Year Member

joined:Oct 1, 2004
posts:607
votes: 0


You could try connecting using the Linux root user's password, if you have that - it's possible they're the same; or try connecting without a password - it's possible (horrible thought) that the root user doesn't have a password (simply use "mysql -u root").

Failing that I assume the password must be stored in the Plesk configuration somewhere if Plesk enables you to create databases. (I don't know Plesk so I've no idea where to look).

9:29 pm on Aug 23, 2006 (gmt 0)

Full Member

10+ Year Member

joined:Aug 16, 2005
posts:240
votes: 0


plesk has its own login, but it doesn't look like I can administer the mysql root login. I guess I can always just create databases along with corresponding logins in plesk and then mysql them in ssh. Oh well.

Thanks for your help.

10:01 pm on Aug 23, 2006 (gmt 0)

Administrator

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 31, 2003
posts:12533
votes: 0


If I remember correctly, plesk rubs out the 'root' user in MySQL and uses a password in
/etc/psa/.psa.shadow

cat /etc/psa/.psa.shadow
will likely show you your password (user is typically 'admin').
9:12 pm on Aug 25, 2006 (gmt 0)

Full Member

10+ Year Member

joined:Aug 16, 2005
posts:240
votes: 0


Cool. Thanks.