All for Joomla All for Webmasters

Praktek melakukan perintah dasar Mysqladmin untuk mengatur MySQL Server

logo_mysqlMySQLAdmin digunakan untuk melakukan konfigurasi pada MySQL Server. Bagi yang ingin belajar menggunakan database ini, ada beberapa perintah yang biasa digunakan dalam MySQL.

1. Bagaimana merubah Password user Root pada MySQL?

Kita asumsikan bahwa password lama yang kita gunakan adalah “123456”, dan password baru adalah “654321” tanpa tanda kutip.

# mysqladmin -u root –p123456 password 654321

Untuk menguji perubahan yang terjadi, silahkan ketik perintah dibawah ini :

# mysql -u root -p654321
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.1.25-rc-community MySQL Community Server (GPL)

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.

mysql>

 

2. Bagaimana mengecek MySQL Server sedang aktif dan berjalan ?
# mysqladmin -u root -p ping
Enter password:
mysqld is alive
 
3. Bagaimana mencari versi MySQL yang anda gunakan ?

# mysqladmin -u root -p654321 version

Hasil jika menggunakan Linux :
mysqladmin  Ver 8.42 Distrib 5.1.25-rc, for redhat-linux-gnu on i686
Copyright (C) 2000-2006 MySQL AB
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL license

Server version          5.1.25-rc-community
Protocol version        10
Connection              Localhost via UNIX socket
UNIX socket             /var/lib/mysql/mysql.sock
Uptime:                 107 days 6 hours 11 min 44 sec

Threads: 1  Questions: 231976  Slow queries: 0  Opens: 17067
Flush tables: 1  Open tables: 64  Queries per second avg: 0.25
Hasil jika menggunakan Windows :
mysqladmin Ver 8.41 Distrib 5.0.22, for Win32 on ia32 Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB This software comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to modify and redistribute it under the GPL license Server version 5.0.22-community-nt-log Protocol version 10 Connection localhost via TCP/IP TCP port 3306 Uptime: 3 hours 7 min 10 sec Threads: 1 Questions: 94 Slow queries: 0 Opens: 0
Flush tables: 1 Open tables: 1 Queries per second avg: 0.008
 
4. Apa status terakhir dari MySQL server anda ?
# mysqladmin -u root -p654321 status
Uptime: 11680
Threads: 1 Questions: 231977 Slow queries: 0 Opens: 17067
Flush tables: 1 Open tables: 64 Queries per second avg: 0.25

Keterangan :

  • Uptime: Uptime dari mysql server dalam detik
  • Threads: Total jumlah client yang terkoneksi pada server.
  • Questions: Total jumlah dari querie yang dijalankan sejak startup.
  • Opens: Total jumlah dari table yang dibuka oleh server.
  • Flush tables: Berapa lama tables di flush.
  • Open tables: Total jumlah table yang dibuka dalam database.
 
5. Bagaimana melihat semua status dari MySQL Server berdasarkan variable dan value saat ini ?
# mysqladmin -u root -p654321 extended-status
+-----------------------------------+-----------+
| Variable_name                     | Value     |
+-----------------------------------+-----------+
| Aborted_clients                   | 579       |
| Aborted_connects                  | 8         |
| Binlog_cache_disk_use             | 0         |
| Binlog_cache_use                  | 0         |
| Bytes_received                    | 41387238  |
| Bytes_sent                        | 308401407 |
| Com_admin_commands                | 3524      |
| Com_assign_to_keycache            | 0         |
| Com_alter_db                      | 0         |
| Com_alter_db_upgrade              | 0         |
 
6. Bagaimana menampilkan semua sistem MySQL server variabel dan values?
# mysqladmin  -u root -p654321 variables
+---------------------------------+---------------------------------+
| Variable_name                   | Value                           |
+---------------------------------+---------------------------------+
| auto_increment_increment        | 1                               |
| basedir                         | /                               |
| big_tables                      | OFF                             |
| binlog_format                   | MIXED                           |
| bulk_insert_buffer_size         | 8388608                         |
| character_set_client            | latin1                          |
| character_set_database          | latin1                          |
| character_set_filesystem        | binary                          |

skip.....

| wait_timeout                    | 28800                           |
+---------------------------------+---------------------------------+
 
7. Bagaimana membuat database dalam MySQL ?
# mysqladmin -u root -p654321 create belajardb

# mysql -u root -p654321
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 705
Server version: 5.1.25-rc-community MySQL Community Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| wordpress          |
| belajardb          |
+--------------------+
4 rows in set (0.00 sec)
 
8. Bagaimana menghapus/delete MySQL database?
# mysqladmin -u root -p654321 drop belajardb
Dropping the database is potentially a very bad thing to do.
Any data stored in the database will be destroyed.

Do you really want to drop the 'belajardb' database [y/N] y
Database “belajardb” dropped

# mysql -u root -p654321
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 707
Server version: 5.1.25-rc-community MySQL Community Server (GPL)

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| wordpress          |
+--------------------+
3 rows in set (0.00 sec)
 
9. Bagaimana melakukan reload/refresh hak akase pada tables?
# mysqladmin -u root -p654321 reload
# mysqladmin -u root -p654321 refresh
 
10. Bagaimana melakukan shutdown yang aman pada MySQL server?
# mysqladmin -u root -p654321 shutdown

# mysql -u root -p654321
ERROR 2002 (HY000): Can't connect to local MySQL server
through socket '/var/lib/mysql/mysql.sock'

NB : Untuk menjalankannya kembali kita tinggal mengetikkan perintah :

Bagi pengguna Linux : /etc/rc.d/init.d/mysql start

Bagi pengguna Windows : X:\MySQL\bin\mysql-nt

Menggabungkan multiple perintah pada mysqladmin.

Didalam menjalankan perintah pada mysqladmin, kita juga dapat menggabungkan beberapa perintah dijalan sekaligus. Umpamanya untuk melihat versi dan juga status dari MySQL Server.

# mysqladmin -u root -p654321 status version

Hasil yang ditampilkan akan terlihat seperti dibawah ini :
Uptime: 3135
Threads: 1  Questions: 80  Slow queries: 0  Opens: 15  Flush tables: 3
Open tables: 0  Queries per second avg: 0.25

mysqladmin  Ver 8.42 Distrib 5.1.25-rc, for redhat-linux-gnu on i686
Copyright (C) 2000-2006 MySQL AB
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL license

Server version          5.1.25-rc-community
Protocol version        10
Connection              Localhost via UNIX socket
UNIX socket             /var/lib/mysql/mysql.sock
Uptime:                 52 min 15 sec

Contoh perintah diatas juga bisa disingkat menjadi seperti dibawah ini :

# mysqladmin  -u root -p654321 pro stat ver

Gunakan opsi -h, untuk koneksi melalui remote ke MySQL server dan langsung menjalankan beberapa perintah mysqladmin.

# mysqladmin -h 192.168.1.1 -u root -p654321 pro stat ver
I'm Teacher Vocational School in SMK Labor Pekanbaru. I interested in Computer, Networking, Web Design, Blogging and the development of computer education.

2 Comments

Leave a Reply

Your email address will not be published.