How do I find out my MySQL URL, host, port and username?
If you're already logged into the command line client try this:
mysql> select user();
It will output something similar to this:
+----------------+
| user() |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.41 sec)
In my example above, I was logged in as root
from localhost
.
To find port number and other interesting settings use this command:
mysql> show variables;
How do I find my host and username on mysql?
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
how to parse mysql database name from database_url
First of all, url.host
would result into:
AttributeError: 'ParseResult' object has no attribute 'host'
use url.hostname
instead.
To get the database_name
out of the provided URL, use path
:
url.path[1:]
An alternative "Don't reinvent the wheel" way to approach the problem would be to use sqlalachemy
's make_url()
, which is regexp-based:
In [1]: from sqlalchemy.engine.url import make_url
In [2]: url = make_url("MYSQL://username:password@host:100/database_name")
In [3]: print url.username, url.password, url.host, url.port, url.database
username password host 100 database_name
How to test which port MySQL is running on and whether it can be connected to?
To find a listener on a port, do this:
netstat -tln
You should see a line that looks like this if mysql is indeed listening on that port.
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN
Port 3306 is MySql's default port.
To connect, you just have to use whatever client you require, such as the basic mysql client.
mysql -h localhost -u user database
Or a url that is interpreted by your library code.
Is there a reason localhost and hostname have no user in tabel user?
These are so-called anonymous users and are described in the mysql manual on default privileges, meaning that these accounts are added by the installer by default:
If accounts for anonymous users were created, these have an empty user
name. The anonymous accounts have no password, so anyone can use them
to connect to the MySQL server.On Windows, there is one anonymous account that permits connections
from the local host. Connections can be made by specifying a host name
of localhost.On Unix, each anonymous account permits connections from the local
host. Connections can be made by specifying a host name of localhost
for one of the accounts, or the actual host name or IP address for the
other.
If you do not need them, you better remove them, or as a minimum, assign password to these accounts.
Related Topics
How to Retrieve Element Value from Soap Response Using Java
Gson Expected Begin_Array But Was String At Line 1 Column 62
Sharing a Variable Between Multiple Different Threads
How to Center Crop a Background Image of Linear Layout
Java.Sql.Sqlexception: Field Doesn't Have a Default Value
Simplifying the If-Else Condition Using Java Functional Style Programming
Keytool Error Bash: Keytool: Command Not Found
Scheduling a Job With Spring Programmatically (With Fixedrate Set Dynamically)
Typecasting an Object from Parent Class to Child
Spring Boot Application Shutdown Immediate After Starting
How to Change Cookie Processor to Legacycookieprocessor in Tomcat 8
Unit Testing Private Functions in Junit With Mockito
Parse Xml to Java Pojo in Efficient Way
Kafka: How to Delete Records from a Topic Using Java API
How to Change the Colors of Text and Background for Cmd in Java