Cannot connect to ODBC DSN - mysql

I want to connect to my ODBC DSN but I always get an error
$conn = new-object system.data.odbc.odbcconnection
$conn.ConnectionString = "Driver={MySQL ODBC 8.0 Unicode Driver};Server=k1000.ad.bac.work;Database=KACE;User=usr;Password=pwd;Option=3"
$conn.Open()
if($conn.Open() -eq $true){
Write-Host "Connection is open"
}
else{
Write-Host "Connection failed"
}
Name : KACE
DsnType : System
Platform : 32-bit
DriverName : MySQL ODBC 8.0 Unicode Driver
Error MSG:Exception calling "Open" with "0" argument(s): "ERROR [HY000] [MySQL][ODBC 8.0(w) Driver]Access denied for user 'usr'#'%' to database 'KACE'
My goal is to get the entire table of a DB in a csv file scripted.

Related

Trouble Connecting to Database Using R

I am trying to connect to an amazonaws.com database using details provided to me. However when I run my code I get the error of
"Error: nanodbc/nanodbc.cpp:1021: 08001: [Microsoft][ODBC Driver 18 for SQL Server]TCP Provider: Timeout error [258]. [Microsoft][ODBC Driver 18 for SQL Server]Login timeout expired [Microsoft][ODBC Driver 18 for SQL Server]Unable to complete login process due to delay in prelogin response."
or
"[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified."
Below are the drivers currently installed on the machine:
[1] "SQL Server"
[2] "ODBC Driver 18 for SQL Server"
[3] "Microsoft Access Driver (*.mdb, *.accdb)"
[4] "Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)"
[5] "Microsoft Access dBASE Driver (*.dbf, *.ndx, *.mdx)"
[6] "Microsoft Access Text Driver (*.txt, *.csv)"
Below are two blocks of code I tried, neither of which successfully connect.
dbConnect(
drv = odbc::odbc(),
driver = "driver",
database = "database",
server = "server",
uid = "username",
pwd = "password")
and
dbConnect(RMySQL::MySQL(),
dbname = "databasename",
host = "amazonawsaddress",
port = port,
user = "username",
password = "password")
Thank you for any suggestions that helps me solve this issue.

I get "SSL Connection Error" when trying to connect to a MySql Server from Powershell

I am trying to work in a connection to a MySql Server database in a powershell script. This is my code:
Add-Type -Path 'C:\Program Files (x86)\MySQL\MySQL Connector Net 8.0.26\Assemblies\v4.5.2\MySql.Data.dll'
$Connection = [MySql.Data.MySqlClient.MySqlConnection]#{
ConnectionString="server=127.0.0.1;port=3306;uid=user;pwd=password;database=example_db"
}
$Connection.Open()
$sql = New-Object MySql.Data.MySqlClient.MySqlCommand
$sql.Connection = $Connection
$sql.CommandText = 'SHOW DATABASES'
$sql.ExecuteNonQuery()
# Close the MySQL connection.
$Connection.Close()
I downloaded the MySql Connector driver and all, but when I execute the code it gets this error output:
Exception calling "Open" with "0" argument(s): "SSL Connection error."
At C:\Users\Path\To\Code\db_con.ps1:9 char:1
+ $Connection.Open()
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : MySqlException
I checked the server, user, pwd and everything checks, I can connect using other clients. Also tried using other valid servers and users, but it just throws this same problem.
Does the server have SSL connections enabled? If not, try adding SslMode=none to the connection string.

How do I connect QT 5.14.1 to MYSQL database?

I tried downloading the sql (sql.lib and sqld.lib) drivers to the MSCV and MINGW files ; it did not work. I then tried through QODBC3 driver and its still not connecting to the database.
I get the following error message.
13:20:05: Starting
C:\build-test1-Desktop_Qt_5_14_1_MinGW_64_bit-Debug\test1.exe ...
13:21:17:
C:\build-test1-Desktop_Qt_5_14_1_MinGW_64_bit-Debug\test1.exe exited
with code 0
//QSqlDatabase db = QSqlDatabase::addDatabase("QODBC3","QMYSQL");
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC3","hello");
// db.setDatabaseName("Driver={MySQL ODBC 8.0 ANSI Driver};DATABASE=hello;");
db.setHostName("127.0.0.1");
db.setDatabaseName("hello");
db.setUserName("localhost");
db.setPassword("");
if (db.open()){
QMessageBox::information(this,"Connection","Database connected succesfully");
}
else {
QMessageBox::information(this,"Connection","Database not connected succesfully");
This is my code, also I did add sql in the pro files.

Connecting to MySQL using encrypted password in PowerShell

I am trying to avoid exposing my password on my connection string while connecting to my MySQL DB via PowerShell but I'm getting the error below:
Exception calling "Open" with "0" argument(s): "Authentication to host 'endpoint' for user 'my_username' using method 'mysql_native_password' failed.
$key = "01000000d08c9ddf0115d1118c7a00c04fc297eb01000000cb490db2b4c9fa44b669d5aef998b678000000000200000000001066000000010000200000003f506a26c5eeddc7620d8f9714d0ccc48968528840746270eba475f13b70a040000000000e80000000020000200000002d6f515408429f78324bc6b3589056810856bd4570fc61c717464e4f42ce691c2000000071d40064ee52a3222e3bcd64a8115d4ae1a3d6dd0daa64e7eab63fb72d5ce6d74000000034b9e0fe42c8fae724eb374a75e250da714372646099dfa076a2329673797ff3e13aedb1b79edcd2685f03802e40d7a43265fe16419acb238966298eda256567"
$password = ConvertTo-SecureString $key
[void][System.Reflection.Assembly]::LoadWithPartialName("MySql.Data")
$cn = New-Object -TypeName MySql.Data.MySqlClient.MySqlConnection
$cn.ConnectionString = "SERVER=$mysql_server;DATABASE=information_schema;UID=$mysql_user;PWD=$password"
$cn.Open()

PHP - The server requested authentication method unknown to the client

I want to connect to a MySQL database from PHP but I can't because "authentication method unknown", I found many solution but all of them about creating a new user with the old password type, but according to the PHP documentation, it should support the new password type. So is it possible to use the new MySQL password type with PHP 7.2.7?
Versions
PHP: 7.2.7MySQL Server: 8.0.12
PHP Code
// Create connection
$conn = new mysqli($servername, $username, $password);
$conn->set_charset("utf8");
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
Result
Connection failed: The server requested authentication method unknown to the client