UbuntuMySQL remote login to Ubuntu
Introduction
Only the successful method is used, not the failure experience. After three days of remote MySQL login, it finally came to an end...
MySQL remote logon
Remote logon command
mysql -h ip(or ipv6) -u username -p userpassword
If-h ip is omitted, MySQL will log on locally by default, that is
mysql -u username -p userpassword
Equivalent
mysql -h localhost -u username -p userpassword
The initial remote login scenario is as follows:
An error occurred while connecting to the remote MySQL database!
Check whether the user is allowed to log on to MySQL remotely.
(%, 127.0.0.1, and localhost indicate that the corresponding user can log on to MySQL locally. linux is a custom host, and the resolved ip address is 127.0.0.1.: 1 is an ipv6 address, point to local Machine)
The figure shows that jinqiang users can log on to MySQL remotely. Why can't they log on remotely?
The problem lies in the MySQL configuration file.
~cat /etc/mysql/my.cnf | grep "^[^#]" -n19:[client]20:port= 330621:socket= /var/run/mysqld/mysqld.sock27:[mysqld_safe]28:socket= /var/run/mysqld/mysqld.sock29:nice= 031:[mysqld]35:user= mysql36:pid-file= /var/run/mysqld/mysqld.pid37:socket= /var/run/mysqld/mysqld.sock38:port= 330639:basedir= /usr40:datadir= /var/lib/mysql41:tmpdir= /tmp42:lc-messages-dir= /usr/share/mysql43:skip-external-locking47:bind-address= 127.0.0.151:key_buffer= 16M52:max_allowed_packet= 16M53:thread_stack= 192K54:thread_cache_size = 857:myisam-recover = BACKUP64:query_cache_limit= 1M65:query_cache_size= 16M77:log_error = /var/log/mysql/error.log89:expire_logs_days= 1090:max_binlog_size = 100M112:[mysqldump]113:quick114:quote-names115:max_allowed_packet= 16M117:[mysql]120:[isamchk]121:key_buffer= 16M127:!includedir /etc/mysql/conf.d/~
Open/etc/mysql/my. cnf
sudo vi /etc/mysql/my.cnf
Set
47: bind-address = 127.0.0.1
Comment out
# Bind-address = 127.0.0.1
Or change it
Bind-address = 192.168.81.93
Restart MySQL
sudo service mysql restart
Try remote login again
Login successful.
C # remote connection to MySQL
Key code (windows environment)
Private void buttonTest_Click (object sender, EventArgs e) {string constr = "host = 192.168.81.93; user = jinqiang; password = 123456; database = test ;"; mySqlConnection mycon = new MySqlConnection (constr); mycon. open (); MySqlCommand mycmd = new MySqlCommand ("insert into employee (id, name, password, email) values (1, 'jinqiang ', '123 ', 'hellojinqiang @ gmail.com ') ", mycon); if (mycmd. executeNonQuery ()> 0) {labelTest. T Ext = "data inserted successfully! ";} Else {labelTest. Text =" data insertion failed! ";}Mycon. Close ();}
PS:
C # connection MySql test code download: http://yunpan.cn/QN7dHwqYPV8i4 (extraction code: b3a1)
In addition, you need to install MySQL Connector Net:
Http://dev.mysql.com/downloads/connector/net/
View Results
(End)