Adding MySQL user via Command Line, Menambah MySQL user dengan Command Line

0
105
Jangan lupa sertakan sumber dengan jelas jika ingin mencopy

1. Connect to machine via ssh - writer using ubuntu 11.04

#ssh -Y bloon@192.168.18.131
bloon@192.168.18.131 €²s password:
Welcome to Ubuntu 11.04 (GNU/Linux 2.6.38-10-generic i686)
* Documentation:   https://help.ubuntu.com/
0 packages can be updated.
0 updates are security updates.
Last login: Thu Aug   4 15:39:40 2011 from 1.1.1.33
bloon@ubuntu:~$

  1. Run as sudo

bloon@ubuntu:~$sudo su

  1. Run mysql

//-h : host mysql server
//-u : username
//-p : password

root@ubuntu:#mysql -h 127.0.0.1 -u root -p
The program mysql can be found in the following packages:
* mysql-client-core-5.1
* mysql-cluster-client-5.1
Try: apt-get install

Oppsss, mysql-client is not installed yet

  1. Install mysql-client

root@ubuntu:#apt-get install mysql-client-core-5.1
Reading package lists
Done Building dependency tree
Reading state information
Done The following packages were automatically installed and are no longer required:   linux-headers-2.6.38-8 linux-headers-2.6.38-8-generic Use apt-get autoremove to remove them. The following extra packages will be installed:   libmysqlclient16 mysql-common The following NEW packages will be installed:   libmysqlclient16 mysql-client-core-5.1 mysql-common 0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
Need to get 1,911 kB of archives.
After this operation, 4,563 kB of additional disk space will be used. Do you want to continue [Y/n]? y
Get:1 http://pandawa.ipb.ac.id/ubuntu/ natty/main mysql-common all 5.1.54-1ubuntu4 [12.2 kB] Get:2 http://pandawa.ipb.ac.id/ubuntu/ natty/main libmysqlclient16 i386 5.1.54-1ubuntu4 [1,808 kB] Get:3 http://pandawa.ipb.ac.id/ubuntu/ natty/main mysql-client-core-5.1 i386 5.1.54-1ubuntu4 [90.8 kB] Fetched 1,911 kB in 22s (86.4kB/s)
Selecting previously deselected package mysql-common.
(Reading database 157049 files and directories currently installed.)
Unpacking mysql-common (from /mysql-common_5.1.54-1ubuntu4_all.deb)
Selecting previously deselected package libmysqlclient16.
Unpacking libmysqlclient16 (from /libmysqlclient16_5.1.54-1ubuntu4_i386.deb)
Selecting previously deselected package mysql-client-core-5.1.
Unpacking mysql-client-core-5.1 (from /mysql-client-core-5.1_5.1.54-1ubuntu4_i386.deb)
Processing triggers for man-db Setting up mysql-common (5.1.54-1ubuntu4) Setting up libmysqlclient16 (5.1.54-1ubuntu4) Setting up mysql-client-core-5.1 (5.1.54-1ubuntu4)
Processing triggers for libc-bin ldconfig deferred processing now taking place

  1. Run mysql client again

bloon@ubuntu:#mysql -h 127.0.0.1 -u root -p
Welcome to the MySQL monitor.
Commands end with ; or g. Your MySQL connection id is 1767 Server version: 5.5.8 Source distribution Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. This software comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to modify and redistribute it under the GPL v2 license
Type help; or h for help. Type c to clear the current input statement.
mysql>

  1. Now create user. There are many ways, this the easiest and fastets on mine

mysql> CREATE USER bego @'localhost IDENTIFIED BY bego_pass ;
mysql> GRANT ALL PRIVILEGES ON *.* TO bego @'localhost   WITH GRANT OPTION;
mysql> CREATE USER bloon @'% IDENTIFIED BY bloon_pass ;
mysql> GRANT ALL PRIVILEGES ON *.* TO bloon @'% WITH GRANT OPTION;
mysql> CREATE USER ndableg @'localhost ;
mysql> GRANT RELOAD,PROCESS ON *.* TO admin @'localhost ;
mysql> CREATE USER blee @'localhost ;

user bego only can be remote from localhost ( bego @ localhost ) dengan akses SU
user bloon can be remote from anywhere( bloon @ % ) dengan akses SU
user ndableg only can be remote from localhost   with limited acces RELOAD dan PROCCESS
user blee only can be accessed from localhost €“ can not be used yet. Can be added in other time
7.   Now, u can test user.   Open new terminal tab (ctrl+shift+t)

root@us-djafa:/home/djafa# mysql -h 192.168.18.131 -u bloon -p
Enter password:
Welcome to the MySQL monitor.
Commands end with ; or g.
Your MySQL connection id is 1872 Server version: 5.5.8 Source distribution Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. This software comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to modify and redistribute it under the GPL v2 license
Type help; or h for help. Type c to clear the current input statement. mysql>

Alhamdulillah proses penambahanMySQL user selesai1. Masuk Server - writer using ubuntu 11.04

#ssh -Y bloon@192.168.18.131
bloon@192.168.18.131 €²s password:
Welcome to Ubuntu 11.04 (GNU/Linux 2.6.38-10-generic i686)
* Documentation:   https://help.ubuntu.com/
0 packages can be updated.
0 updates are security updates.
Last login: Thu Aug   4 15:39:40 2011 from 1.1.1.33
bloon@ubuntu:~$

  1. Jalankan sudo secara explicit

bloon@ubuntu:~$sudo su

  1. Jalankan mysql-client ( Untuk menambah user, anda harus mempunyai user mysql dengan privileges full atau setidaknya menambah user)

//-h : host mysql server
//-u : username
//-p : password

root@ubuntu:#mysql -h 127.0.0.1 -u root -p
The program mysql can be found in the following packages:
* mysql-client-core-5.1
* mysql-cluster-client-5.1
Try: apt-get install

Oppsss, mysql-client is not installed yet

  1. Install mysql-client

root@ubuntu:#apt-get install mysql-client-core-5.1
Reading package lists
Done Building dependency tree
Reading state information
Done The following packages were automatically installed and are no longer required:   linux-headers-2.6.38-8 linux-headers-2.6.38-8-generic Use apt-get autoremove to remove them. The following extra packages will be installed:   libmysqlclient16 mysql-common The following NEW packages will be installed:   libmysqlclient16 mysql-client-core-5.1 mysql-common 0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
Need to get 1,911 kB of archives.
After this operation, 4,563 kB of additional disk space will be used. Do you want to continue [Y/n]? y
Get:1 http://pandawa.ipb.ac.id/ubuntu/ natty/main mysql-common all 5.1.54-1ubuntu4 [12.2 kB] Get:2 http://pandawa.ipb.ac.id/ubuntu/ natty/main libmysqlclient16 i386 5.1.54-1ubuntu4 [1,808 kB] Get:3 http://pandawa.ipb.ac.id/ubuntu/ natty/main mysql-client-core-5.1 i386 5.1.54-1ubuntu4 [90.8 kB] Fetched 1,911 kB in 22s (86.4kB/s)
Selecting previously deselected package mysql-common.
(Reading database 157049 files and directories currently installed.)
Unpacking mysql-common (from /mysql-common_5.1.54-1ubuntu4_all.deb)
Selecting previously deselected package libmysqlclient16.
Unpacking libmysqlclient16 (from /libmysqlclient16_5.1.54-1ubuntu4_i386.deb)
Selecting previously deselected package mysql-client-core-5.1.
Unpacking mysql-client-core-5.1 (from /mysql-client-core-5.1_5.1.54-1ubuntu4_i386.deb)
Processing triggers for man-db Setting up mysql-common (5.1.54-1ubuntu4) Setting up libmysqlclient16 (5.1.54-1ubuntu4) Setting up mysql-client-core-5.1 (5.1.54-1ubuntu4)
Processing triggers for libc-bin ldconfig deferred processing now taking place

  1. Ok, mysql-client sudah dipasang. Sekarang jalankan mysql-client.

Perintahnya adalah : mysql -h host - u user -p

bloon@ubuntu:#mysql -h 127.0.0.1 -u root -p
Welcome to the MySQL monitor.
Commands end with ; or g. Your MySQL connection id is 1767 Server version: 5.5.8 Source distribution Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. This software comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to modify and redistribute it under the GPL v2 license
Type help; or h for help. Type c to clear the current input statement.
mysql>

  1. Jika sudah bisa masuk dengan akses full, sekarang buat user. Ada beberapa cara, namun berikut ini adalah yang penulis anggap paling mudah.

mysql>  CREATE USER bego @'localhost IDENTIFIED BY bego_pass ;
mysql>  GRANT ALL PRIVILEGES ON *.* TO bego @'localhost    WITH GRANT OPTION;  
mysql>  CREATE USER bloon @'% IDENTIFIED BY bloon_pass ;
mysql>  GRANT ALL PRIVILEGES ON *.* TO bloon @'%  WITH GRANT OPTION;
mysql>  CREATE USER ndableg @'localhost ;
mysql>  GRANT RELOAD,PROCESS ON *.* TO admin @'localhost ;
mysql>  CREATE USER blee @'localhost ;

user  bego  hanya bisa masuk dari localhost ( bego @ localhost ) dengan akses SU
user  bloon bisa masuk dari mana saja  ( bloon @ % ) dengan akses SU
user  ndableg  hanya bisa masuk dari localhost dengan akses terbatas, RELOAD dan PROCCESS
user  blee  hanya bisa di akses dari localhost namun belum diaktifkan. Bisa dilakukan lain waktu
7.  Test user.  Buka terminal baru (ctrl+shift+t)

root@us-djafa:/home/djafa# mysql -h 192.168.18.131 -u bloon -p
Enter password:
Welcome to the MySQL monitor.
Commands end with ; or g.
Your MySQL connection id is 1872 Server version: 5.5.8 Source distribution Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. This software comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to modify and redistribute it under the GPL v2 license
Type help; or h for help. Type c to clear the current input statement. mysql>

Alhamdulillah proses penambahanMySQL user selesai

Advertisements

Jangan lupa tinggalkan komentar ya gais

This site uses Akismet to reduce spam. Learn how your comment data is processed.