Audel
Audel

Reputation: 2509

How do I find my host and username on mysql?

I need to open my database through PHP. But I need to know my username and the name of my host (e.g. localhost), and I don't know them.

When I used mysql and did my database, it just asked me directly for a password.

How do I find my host and username on mysql?

Upvotes: 26

Views: 162173

Answers (5)

aadilraza339
aadilraza339

Reputation: 69

This is how you can open MySQL shell

\connect root@localhost:3306

Upvotes: -1

d-coder
d-coder

Reputation: 1200

type this command

select CURRENT_USER();

You will get the username and server

Upvotes: 28

adharris
adharris

Reputation: 3661

The default username is root. You can reset the root password if you do not know it: http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html. You should not, however, use the root account from PHP, set up a limited permission user to do that: http://dev.mysql.com/doc/refman/5.1/en/adding-users.html

If MySql is running on the same computer as your webserver, you can just use "localhost" as the host

Upvotes: 22

antyrat
antyrat

Reputation: 27765

Default user for MySQL is "root", and server "localhost".

Upvotes: 10

JSBձոգչ
JSBձոգչ

Reputation: 41378

You should be able to access the local database by using the name localhost. There is also a way to determine the hostname of the computer you're running on, but it doesn't sound like you need that. As for the username, you can either (1) give permissions to the account that PHP runs under to access the database without a password, or (2) store the username and password that you need to connect with (hard-coded or stored in a config file), and pass those as arguments to mysql_connect. See http://php.net/manual/en/function.mysql-connect.php.

Upvotes: 2

Related Questions