How to connect to MySQL using .NET Core How should I write the connection string?
Copyright Notice: This article is an original work licensed under the CC 4.0 BY-NC-ND license.
If you wish to repost this article, please include the original source link and this copyright notice.
Source link: https://v2know.com/article/499
MySQL Connector/Net (.NET) standard connection method
1. Standard connection (Note, the default port is 3306.)
Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
2. Special TCP/IP port connection
Server=myServerAddress;Port=1234;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
Local connection should write
Server=/var/run/mysqld/mysqld.sock
As for localhost and 127.0.0.1, if you can use it, it is recommended to write localhost, because localhost does not go through the network layer, firewall, etc., theoretically the performance is higher.
But when I was testing, neither localhost nor 127.0.0.1 could be used, but the public IP was fine...
It was also strange at the time, and then I thought it was because I commented out the similar statement bind localhost=127.0.0.1 in a configuration file.
But this is not going to be verified, and I will add it later.
This article was last edited at 2020-11-04 16:08:20