remote server connect with mysql - mysql

I have mysql 5.1 set up and running.
I need to connect to:
location: comm.eng.bxg.com
name: amntxy
user: username
pswd: password
I have tried using
mysql -h amntxy -u username -p
Also tried: use amntxy and use comm.eng.bxg.com/amntxy
But I am unable to connect.
I get the following error:
ERROR 2005 (HY000): Unknown MySQL server host
I also tried mysql_connect but keep getting the error : mysql_connect is not recognized as internal or external command
But I do not understand hwo I can connect here.
Please help.
Thank you

mysql -h comm.eng.bxg.com -u username -p
After this it will ask for a password.
Optionally you can also directly specify the database name that you want:
mysql -h comm.eng.bxg.com -u username -p db_name
But again, this is 100% optional. You will be able to select or change it after with the command USE db_name.

Related

Mysql ERROR : not connected

I am trying to connect to MySQL database from MySQL shell on windows.
No matter what I type in MySQL shell, it keeps giving me error : 'Not connected'.
Query eg 1 : mysql --host=localhost --port=3306 --user=root -p;
Query eg 2 : mysql -u root -p
O/P : ERROR: Not connected
I have MySQL server installed on my machine. Also MySQL service is running in the background.
Also, I was able to connect from MySQL workbench.
ERROR MESSAGE
MySQL Workbench Connection
My temporary workaround is that I make use of ssl protocol to connect to MySQL server :
MySQL> \connect root#localhost
MySQL localhost:33060+ ssl SQL > show databases;
The first step is that you need to check if you are in the MYSQL Shell SQL mode or JS mode.
Then if you are in SQL mode then you are good to go else you need to switch to SQL mode by this command
\sql
The next step is to connect using this command
\connect root#localhost
In your case, you might have given the privilege as the IP address so you need to check your localhost IP which can be done by this command in your command prompt.
ipconfig and then just check the IP address and put it in place of localhost in the previous command. If this still doesn't works then put 127.0.0.1:3306.
After this, it will prompt to add or save the password , enter a unique password there.
After this you are good to go and check the user and localhost after this by this command
SELECT user, host FROM mysql.user;
Try mysql -u root -p
I haven't used MySQL shell, I typically use gitbash and it works just fine
I had faced the same issue on my Windows 10 machine with MySQL 5.7 and the following commands helped me:
mysqlsh.exe - to open mysql shell; then
\sql - to start working with SQL;
finally:
\connect root#127.0.0.1:3306
You can use:
mysql -uroot -hlocalhost -P3306 -p
or
mysql -uroot -h127.0.0.1 -P3306 -p
or
mysql -uroot -p

Mysql[MariaDB] - Unknow error 1130

I'm trying to connect to a database and I'm getting this error:
ERROR 1130 (HY000): Unknown error 1130
Here is a command which I'm using:
mysql --host HOSTNAME --user MYUSERNAME -p MYDATABASENAME
I'm using Arch Linux. Thanks in advance for the help !
mysql --host HOSTNAME --user MYUSERNAME -p MYDATABASENAME
MYDATABASENAME - Should be Password not DatabaseName..
Syntax:
shell> mysql --host=localhost --user=myname --password=password mydb
shell> mysql -h localhost -u myname -ppassword mydb
Ref: https://dev.mysql.com/doc/refman/5.7/en/connecting.html
ERROR 1130 translates into Host '<hostname/IP>' is not allowed to connect to this MariaDB server, not sure why you see it as unknown error.
It means that there are no users configured with host=<your hostname/IP> on the server where you are connecting to -- that is, there is no user MYUSERNAME#<your hostname/IP>, or even <anything>#<your hostname/IP>, or <anything>#'%'.
Hi this is similar to phpMyAdmin Remote Access
Basically you have to first configure remote access. Here is a link for MariaDB on Arch Linux remote access configuration. https://dominicm.com/install-mysql-mariadb-on-arch-linux/
Edit config locally.
Config file sudo nano /etc/mysql/my.cnf
Grant privilege to table for user
GRANT ALL PRIVILEGES ON databasename.* TO 'dbusername'#'%' IDENTIFIED BY 'dbpassword';
Restart Mysql/MariaDB
Hopefully this helps.
try mysqld --skip-grant-table
Not sure why but it helped my teammate as she reported.
More details here. https://www.howtoforge.com/setting-changing-resetting-mysql-root-passwords

How do i connect to the Live database(Mysql) using Mysql command prompt?

I have tried the following command syntax to connect with live
database...
-u Username -pPassword -h HostName Database Name
But there is an error
ERROR 1064 (42000): You have an error in your SQL syntax; check the
manual that corresponds to your MYSQL server version for the right
syntax to use near ' -u Username -pPassword -h HostName Database Name'
The command you're describing is for connecting to the database in command line. If you need to connect to a database inside a PHP script, you must use:
mysqli_connect aka mysqli::__construct
PDO::__construct
I'm not recommending it but if you're stuck with legacy code, mysql_connect also does the same for the deprecated mysql_* extension.
Try this... This might help you
connect to mysql database using command line and php
You must be using this command already on mysql shell prompt or on phpmyadmin like sql frontend. You must not use this command on mysql-shell as you are already loggin into mysql. Try this command on bash shell on linux or dos prompt on windows.
mysql -u Username -pPassword -h HostName DatabaseName
One more thing, If you are using windows (like wamp/xampp). You may need to pass full mysql path like
c:\wamp\bin\mysql\mysql -u Username -pPassword -h HostName DatabaseName

MySQL Error:10061

Apparently, I cannot connect to SQL server using the mysql.exe
I logged in as the root user and typed the following
mysql -u root -p
mysql> CONNECT TO 127.0.0.1:3306;
I receive the folling error.
ERROR 2005 (HY000): Unknown MySQL server host '127.0.01:3306' (2)
Unknown MySQL server host '127.0.0.1:3306' (2)
However it connects justs fine using MySQL Workbench with the same parameters.
Host:127.0.0.1
Port:3306
User: root
pass:[empty]
I have the easyphp MySQL module installed. Could this be the reason?
EDIT: TYPO with 127.0.0.1 sorry
According to the documentation, the syntax of the connect command is:
connect [db_name host_name]], \r [db_name host_name]]
Reconnect to the server. The optional database name and host name arguments may be given to specify the default database or the host where the server is running. If omitted, the current values are used.
Therefore your command CONNECT TO 127.0.0.1:3306 is attempting to connect to a database called TO on a host called 127.0.0.1:3306. The error message you receive in return unsurprisingly complains that the host does not exist.
However, it is more usual to specify the hostname and database on invoking mysql (whereupon one can also specify the port if one wishes - see this page for a full list of command line options):
mysql -u username -p -h <hostname> -P <port> db_name
Also note that if the hostname and port are not specified, they default to localhost and 3309 - therefore in your case you can omit all of the above and just go with:
mysql -u username -p db_name
To do what you're currently doing (not specifying the database name on the command-line), you must call the USE command at the mysql> prompt to select a database after you've connected:
mysql -u username -p
mysql> USE db_name;
127.0.01 is explicitly misspelled. 127.0.0.1 is correct
127.0.01:3306 IS NOT 127.0.0.1:3306
You forgot the dot.

php can connect to remote sql server but command line can't

I'm using exactly the same credentials to connect to a remote mysql server.
host % is given to the user.
I can connect via my php application on localhost to remote mysql server
however whenever i do command line on localhost
mysql -u username -p'password' -h remoteserver.domain.com
it throws an error
ERROR 1045 (28000): Access denied for user 'username'#'10.50.2.4' (using
password: YES)
what am i missing here?
Your mysql command line is wrong. Mysql has the funky syntax of:
mysql -u username -ppassword -h remoteserver.domain.com
instead of
mysql -u username -p password -h remoteserver.domain.com
Note the p tag and password placement.
turns out that i should do away single quotes in my password for windows-based mysql command
instead of
mysql -u username -p'password' -h remoteserver.domain.com
this actually works
mysql -u username -ppassword -h remoteserver.domain.com
reason why i use single quotes because my password contains non-alpha characters which works in linux but not on windows based command line