In earlier post we saw how to Install and configure MySQL on CentOS7/RHEL7 machines. Now we would how we could connect MySQL Server from Unix/Linux command line mysql client. So for this post our topic is HowTo connect disconnect MySQL Server.

For this setup, we are using CentOS7 latest as of now.


[root@localhost ~]# uname  -r

[root@localhost ~]# cat /etc/redhat-release 
CentOS Linux release 7.4.1708 (Core) 

[root@localhost ~]# mysqlcheck --version
mysqlcheck  Ver 2.7.2-MariaDB Distrib 5.5.56-MariaDB, for Linux (x86_64)

We can connect to MySQL through Linux/Unix machine through mysql client installed on Linux/Unix Machine as mentioned in previous post. So we could connect MySQL Server through below mentioned way and access mysql console which help to run SQL command for database queries.

Binary Used

MySQL Client binary used to connect MySQL Server is installed with mariadb RPM Package described below.

[root@localhost ~]# which  mysql

[root@localhost ~]# rpm -qf /bin/mysql


We can connect it with following Syntax.

# mysql -u UserName -h Hostname -p


Here we have to provide user-name, hostname and user’s password. In case we connect to localhost we don’t need to mention Hostname as it will directly try to connect to local default socket used for MySQL Server.

[root@localhost ~]# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 6
Server version: 5.5.56-MariaDB MariaDB Server

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> 

Now we are connected to local MySQL Server and can run SQL command against database stored in MySQL Server.

MariaDB [(none)]> status;
mysql  Ver 15.1 Distrib 5.5.56-MariaDB, for Linux (x86_64) using readline 5.1

Connection id:		6
Current database:	
Current user:		root@localhost
SSL:			Not in use
Current pager:		stdout
Using outfile:		''
Using delimiter:	;
Server:			MariaDB
Server version:		5.5.56-MariaDB MariaDB Server
Protocol version:	10
Connection:		Localhost via UNIX socket
Server characterset:	latin1
Db     characterset:	latin1
Client characterset:	utf8
Conn.  characterset:	utf8
UNIX socket:		/var/lib/mysql/mysql.sock
Uptime:			28 min 50 sec

Threads: 1  Questions: 15  Slow queries: 0  Opens: 0  Flush tables: 2  Open tables: 26  Queries per second avg: 0.008


For disconnection from MySQL client,we need to exit from command line console or do ctl+d

MariaDB [(none)]> exit

How to upgrade Maridb on CentOS7/RHEL7