Re: any environment like MYSQL_UNIX_PORT to specify socket path
Hello,
MySQL Shell supports that.
Example specifying the socket:
$ mysqlsh -S /var/lib/mysql/mysql.sock
Please provide the password for 'fred@/var%2Flib%2Fmysql%2Fmysql.sock': *********
Save password for 'fred@/var%2Flib%2Fmysql%2Fmysql.sock'? [Y]es/[N]o/Ne[v]er (default No): yes
MySQL Shell 8.3.0
Copyright (c) 2016, 2023, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates.
Other names may be trademarks of their respective owners.
Type '\help' or '\?' for help; '\quit' to exit.
Creating a session to 'fred@/var%2Flib%2Fmysql%2Fmysql.sock'
Fetching schema names for auto-completion... Press ^C to stop.
Your MySQL connection id is 10
Server version: 8.3.0 MySQL Community Server - GPL
No default schema selected; type \use <schema> to set one.
MySQL localhost 2024-03-20 08:44:54
JS \s
MySQL Shell version 8.3.0
Connection Id: 10
Current schema:
Current user: fred@localhost
SSL: Not in use.
Using delimiter: ;
Server version: 8.3.0 MySQL Community Server - GPL
Protocol version: Classic 10
Client library: 8.3.0
Connection: Localhost via UNIX socket
Unix socket: /var/lib/mysql/mysql.sock
Server characterset: utf8mb4
Schema characterset: utf8mb4
Client characterset: utf8mb4
Conn. characterset: utf8mb4
Result characterset: utf8mb4
Compression: Disabled
Uptime: 12 hours 50 min 18.0000 sec
Threads: 2 Questions: 21 Slow queries: 0 Opens: 157 Flush tables: 3 Open tables: 74 Queries per second avg: 0.000
This was to test if the socket connection was working.
Now specifying the socket using MYSQL_UNIX_PORT:
$ export MYSQL_UNIX_PORT=/var/lib/mysql/mysql.sock
$ mysqlsh root@localhost
MySQL Shell 8.3.0
Copyright (c) 2016, 2023, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates.
Other names may be trademarks of their respective owners.
Type '\help' or '\?' for help; '\quit' to exit.
Creating a session to 'root@localhost'
Fetching schema names for auto-completion... Press ^C to stop.
Your MySQL connection id is 11 (X protocol)
Server version: 8.3.0 MySQL Community Server - GPL
No default schema selected; type \use <schema> to set one.
MySQL localhost:33060+ 2024-03-20 08:45:30
JS \s
MySQL Shell version 8.3.0
Connection Id: 11
Default schema:
Current schema:
Current user: root@::1
SSL: Cipher in use: TLS_AES_128_GCM_SHA256 TLSv1.3
Using delimiter: ;
Server version: 8.3.0 MySQL Community Server - GPL
Protocol version: X protocol
Client library: 8.3.0
Connection: localhost via TCP/IP
TCP port: 33060
Server characterset: utf8mb4
Schema characterset: utf8mb4
Client characterset: utf8mb4
Conn. characterset: utf8mb4
Result characterset: utf8mb4
Compression: Enabled (DEFLATE_STREAM)
Uptime: 12 hours 50 min 57.0000 sec
And to ensure it uses the variable (using a non existing socket file):
$ export MYSQL_UNIX_PORT=/var/lib/mysql/mysql2.sock
$ mysqlsh mysql://root@localhost
MySQL Shell 8.3.0
Copyright (c) 2016, 2023, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates.
Other names may be trademarks of their respective owners.
Type '\help' or '\?' for help; '\quit' to exit.
Creating a Classic session to 'root@localhost'
MySQL Error 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql2.sock' (2)
I hope this helps.
Please note that I specify the protocol in the URI: mysql://root@localhost
This is required as per default MySQL Shell will use the X protocol that uses another socket too of course:
$ export MYSQL_UNIX_PORT=/var/run/mysqld/mysqlx.sock
$ mysqlsh root@localhost
MySQL Shell 8.3.0
Copyright (c) 2016, 2023, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates.
Other names may be trademarks of their respective owners.
Type '\help' or '\?' for help; '\quit' to exit.
Creating a session to 'root@localhost'
Fetching schema names for auto-completion... Press ^C to stop.
Your MySQL connection id is 13 (X protocol)
Server version: 8.3.0 MySQL Community Server - GPL
No default schema selected; type \use <schema> to set one.
MySQL localhost:33060+ 2024-03-20 08:54:07
JS \s
MySQL Shell version 8.3.0
Connection Id: 13
Default schema:
Current schema:
Current user: root@::1
SSL: Cipher in use: TLS_AES_128_GCM_SHA256 TLSv1.3
Using delimiter: ;
Server version: 8.3.0 MySQL Community Server - GPL
Protocol version: X protocol
Client library: 8.3.0
Connection: localhost via TCP/IP
TCP port: 33060
Server characterset: utf8mb4
Schema characterset: utf8mb4
Client characterset: utf8mb4
Conn. characterset: utf8mb4
Result characterset: utf8mb4
Compression: Enabled (DEFLATE_STREAM)
Uptime: 12 hours 59 min 32.0000 sec
Regards,
Subject
Views
Written By
Posted
245
March 16, 2024 09:22PM
Re: any environment like MYSQL_UNIX_PORT to specify socket path
137
March 20, 2024 01:55AM
Sorry, only registered users may post in this forum.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.