You need to use the show databases SQL command. First you need to login as MySQL database root user using mysql command line client. Type the following command to login with a password at a shell prompt:
$ mysql -u USERNAME -h HOSTNAME -p
$ mysql -u root -p
At mysql prompt type the following command (show databases;):
mysql> show databases;
Sample output:
+--------------------+ | Database | +--------------------+ | information_schema | | mysql | | wiki | +--------------------+ 3 rows in set (0.03 sec)
Of course your can use the following shell one liner to get the list of all databases too:
# Connect to the local server mysql -u root -h localhost -p -e 'show databases;' # Connect to the remove mysql server mysql -u root -h 192.168.1.250 -p -e 'show databases;'
Sample outputs:
Fig.01: mysql command in action
mysql -u root -h localhost -p'MyPasswordHere' -e 'show databases;' | awk '{ print $1 }' # OR store it in $DBS shell variable DBS=$(mysql -u root -h localhost -p'MyPasswordHere' -e 'show databases;' | awk '{ print $1 }') echo "List of database - $DBS"
🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.
🐧 5 comments so far... add one ↓
🐧 5 comments so far... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
for me some of the databases are not listing wven though complete privilleges are given and i checked same on mysql.db table also .Please help me out
from script
mysql -u username -pxxxxxx -Bse ‘show databases’
thanks :)
Task: Develop a PHPMyAdmin Input: Hostname, Username, Password.
Output: List all databases & table names which are associated with the given username & password.please guys,can anyone tell me how to do it?thanks in advance
Thanks. It was really useful.