I am trying to figure out what the mysql -u root -p command does.
I have googled the command but I can't find any good results.
mysql -u root -p means, that you trying to connect to MySQL shell with parameters - -u parameter specified MySQL user name.
-u, --user=name User for login if not current user.
In your case it's root user.
-p, --password[=name]
Password to use when connecting to server. If password is
not given it's asked from the tty.
You can type mysql --help from the command line for more information about all available parameters.
Good luck.
It logs you into mysql as the root user. After -p (Immediately after it incidentally, no spaces) you would include the password.
`mysql -u root -p`
Its initiate a connection of MySQL.
-u means that we are going to connect with a username root
-p means that we will enter username's password
Check man mysql
Your command tries to connect to MySQL on localhost with user "root" and asking for a password
So I am installing snort currently on my ubuntu linux server. I am following this guide here.
At this point, I am at the part in the guide where I am installing Barnyard2 and i need to access my SQL database to save information. linux server is near fresh install with little else on it. When I try to do this part of the guide:
echo "create database snort;" | mysql -u root -p
mysql -u root -p -D snort < ~/snort_src/barnyard2-master/schemas/create_mysql
echo "grant create, insert, select, delete, update on snort.* to \
snort#localhost identified by 'MYSQLSNORTPASSWORD'" | mysql -u root -p
When I run the first line - if I don't enter anything, I get the error message that says:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
If I do enter something, I get a different error:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
I have tried using this in order to reset my password but the command mysql -u root or any form of command similiar results back in the same error, even when it says the password is probably not required for this command. Does anyone know a way in which I can get this to work?
Why don't you break that down into chunks?
First make the database:
$ mysql -u root -p -e 'CREATE DATABASE `snort`'
Import the barnyard schema
$ mysql -u root -p < ~/snort_src/barnyard2-master/schemas/create_mysql
Now create the user & assign permissions for the snort db to the barnyard user
$ mysql -u root -p -e 'GRANT CREATE, INSERT, SELECT, DELETE, UPDATE ON `snort`.* TO snort#localhost IDENTIFIED BY '[SNORT PASSSWORD]'
The commands in your question are running a local mysql client which assumes to connect to a local database by default. If your database is running on a neighbouring Windows box you will need to rethink your parameters.
mysql -u root -p -h 192.168.0.99
After a while (weeks) not working with MySQL 5.5.41-0ubuntu0.14.04.1-log, now when I try to connect I get:
$ mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'#'DD.D.DDD.DDD' (using password: YES)
(D are the digits of my external IP)
I have no problem if I use
$ mysql -u root -p -h localhost
Why is it now using my external IP? I have no changes under /etc/mysql
left in a vacuum it guess since you did not specify -h host in first attempt. It marches down mysql.user and finds the first match for the wildcard. And your entered password did not match it.
running a select * from mysql.user might shed some light on it. You might find entries such as:
Host User
172.31.2.202 root
localhost root
% root
127.0.0.1 root
Edit:
Sometimes you need to do a:
CREATE USER 'root'#'www.xxx.yyy.zzz' IDENTIFIED BY 'new_password';
Followed by the necessary grants for that user. Above where I say root, it is just an example. I would not do root !
Also, do not put a space after -u, so it is not -u root, it is -uroot
I am trying the following mysql command:
zcat ***.sql.gz | mysql -u root -p dbname
Maybe the question applies equally to the following, simpler command:
mysql -u root -p dbname
You can find this kind of snippet all over the internet, and it usually works. It should prompt you for the db user's password (in this case, the db root pw), and then use "dbname" as the database name. Only today it did NOT ask me for the root pw, and instead just said
Access denied for user 'root'#'localhost' (using password: YES)
I assume that in this case mysql thought that "dbname" is the password. I just don't understand why in the usual case it understands that "dbname" is the database name.
I have also seen this variation:
mysql -u root -pthepassword dbname
Here the interesting thing is that -u is followed by a space, but -p is not.
The question: How does mysql distinguish the dbname from the password?
I have a server with Rackspace. I want to access the database from my local machine command line.
I tried like:
mysql -u username -h my.application.com -ppassword
But it gives an error:
ERROR 2003 (HY000):
Can't connect to MySQL server on 'my.application.com' (10061)
What causes this error and how can I connect to the remote database?
To directly login to a remote mysql console, use the below command:
mysql -u {username} -p'{password}' \
-h {remote server ip or name} -P {port} \
-D {DB name}
For example
mysql -u root -p'root' \
-h 127.0.0.1 -P 3306 \
-D local
no space after -p as specified in the Using Options on the Command Line documentation
It will take you to the mysql console directly by switching to the mentioned database.
simply put this on terminal at ubuntu:
mysql -u username -h host -p
Now hit enter
terminal will ask you password, enter the password and you are into database server
edit my.cnf file:
vi /etc/my.cnf:
make sure that:
bind-address=YOUR-SERVER-IP
and if you have the line:
skip-networking
make sure to comment it:
#skip-networking
don't forget to restart:
/etc/init.d/mysqld restart
For Mac, use the following command:
mysql -u app -h hostaddress -P port -D dbname -p
and then enter the password when prompted.
If you want to not use ssh tunnel, in my.cnf or mysqld.cnf you must change 127.0.0.1 with your local ip address (192.168.1.100) in order to have access over the Lan. example bellow:
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
Search for bind-address in my.cnf or mysqld.cnf
bind-address = 127.0.0.1
and change 127.0.0.1 to 192.168.1.100 ( local ip address )
bind-address = 192.168.1.100
To apply the change you made, must restart mysql server using next command.
sudo /etc/init.d/mysql restart
Modify user root for lan acces ( run the query's bellow in remote server that you want to have access )
root#192.168.1.100:~$ mysql -u root -p
..
CREATE USER 'root'#'%' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'root'#'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
If you want to have access only from specific ip address , change 'root'#'%' to 'root'#'( ip address or hostname)'
CREATE USER 'root'#'192.168.1.100' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'root'#'192.168.1.100' WITH GRANT OPTION;
FLUSH PRIVILEGES;
Then you can connect:
nobus#xray:~$ mysql -h 192.168.1.100 -u root -p
tested on ubuntu 18.04 server
Try this command mysql -uuser -hhostname -PPORT -ppassword.
I faced a similar situation and later when mysql port for host was entered with the command, it was solved.
try telnet 3306. If it doesn't open connection, either there is a firewall setting or the server isn't listening (or doesn't work).
run netstat -an on server to see if server is up.
It's possible that you don't allow remote connections.
For more details see:
How Do I Enable Remote Access To MySQL Database Server?
I assume you have MySQL installed on your machine. Execute the command below after filling missing details:
mysql -uUSERNAME -pPASSWORD -hHOSTNAME -P3306
mysql servers are usually configured to listen only to localhost (127.0.0.1), where they are used by web applications.
If that is your case but you have SSH access to your server, you can create an ssh tunnel and connect through that.
On your local machine, create the tunnel.
ssh -L 3307:127.0.0.1:3306 -N $user#$remote_host
(this example uses local port 3307, in case you also have mysql running on your local machine and using the standard port 3306)
Now you should be ale to connect with
mysql -u $user -p -h 127.0.0.1 -P 3307
There is simple command.
mysql -h {hostip} -P {port} -u {username} -p {database}
Example
mysql -h 192.16.16.2 -P 45012 -u rockbook -p rockbookdb
you can use the following code to connect to a remote MY SQL database
mysql -u {database_user} -p{db_password} -h {host_name} -P {port_number}
mysql -u admin -p'your_password' -h your-company.aws.com -P 3306
Must check whether incoming access to port 3306 is block or not by the firewall.
this solution worked for me:
On your remote machine (example: 295.13.12.53) has access to your target remote machine (which runs mysql server)
ssh -f -L 295.13.12.53:3306:10.18.81.36:3306 user#295.13.12.53
Explained:
ssh -f -L your_ssh_mashine_ipaddress:your_ssh_mashine_local_port:target_ipaddress:target_port user#your_ip_address -N
your_ssh_mashine_ipaddress - it is not local ip address, it is ip address
that you ssh to, in this example 295.13.12.53
your_ssh_mashine_local_port -this is custom port not 22, in this example it is 3306.
target_ipaddress - ip of the machine that you trying to dump DB.
target_port - 3306 this is real port for MySQL server.
user#your_ip_address - this is ssh credentials for the ssh mashine that you connect
Once all this done then go back to your machine and do this:
mysqldump -h 295.13.12.53 -P 3306 -u username -p db_name > dumped_db.sql
Will ask for password, put your password and you are connected.
Hope this helps.
Try this, Its working:
mysql -h {hostname} -u{username} -p{password} -N -e "{query to execute}"
This one worked for me in mysql 8, replace hostname with your hostname and port_number with your port_number, you can also change your mysql_user if he is not root
mysql --host=host_name --port=port_number -u root -p
Further Information Here
You should put your password with 'p'
mysql -u root -u 1.1.1.1 -p'MyPass'
I was too getting the same error.
But found it useful by creating new mysql user on remote mysql server ans then connect. Run following command on remote server:
CREATE USER 'openvani'#'localhost' IDENTIFIED BY 'some_pass';
GRANT ALL PRIVILEGES ON *.* TO 'openvani'#'localhost WITH GRANT
OPTION;
CREATE USER 'openvani'#'%' IDENTIFIED BY 'some_pass';
GRANT ALL PRIVILEGES ON *.* TO 'openvani'#'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
Now you can connect with remote mysql with following command.
mysql -u openvani -h 'any ip address'-p
Here is the full post:
http://openvani.com/blog/connect-remotely-mysql-server/
If you are on windows, try Visual Studio Code with MySQL plugins, an easy and integrated way to access MySQL data on a windows machine. And the database tables listed and can execute any custom queries.
If port is default, some version required data base name which you trying to connect.
mysql -u <<your username>> -h <<your host>> <<your db name >> -p
This will prompt password Then type your password. If port is not default 3306
Then:
mysql -u <<your username>> -h <<your host>> -P <<your port>> <<your db name >> -p