- Laporkan artikel ini
Laporan
Laporan
Kembali Kirim
Piyush Diwakar
MySQL. Mongo. Pergeseran merah. AWS. Peramal. Sr. DBA di Paytm Money. Mantan RAKUTEN. Mantan Innoeye
Diterbitkan 11 Februari 2021
+ Ikuti
Dalam tutorial ini, saya akan memandu Anda bagaimana mengubah port default mysql dan apa tujuan dari mysql_secure_installation
Di bawah ini adalah apa yang akan kami lakukan untuk tujuan ini
- Hentikan Layanan MySQL
- Ubah port di File Konfigurasi MySQL
- Mulai ulang Layanan MySQL
- Jalankan Skrip Keamanan [mysql_secure_installation]
- Ubah kata sandi untuk root
- Hapus pengguna anonim
- Larang login root dari jarak jauh
- Hapus basis data pengujian dan akses ke sana
- Muat ulang tabel hak istimewa sekarang
- Login ke MySQL Shell dengan Kata Sandi Baru
Langkah 1 - Hentikan Layanan MySQL
Untuk CentOS
[root@DBA-Master ~]# service mysqld stop
Untuk Ubuntu
[root@DBA-Master ~]# service mysql stop_
Langkah 2 - Ubah Port di File Konfigurasi MySQL
Untuk CentOS
[root@DBA-Master ~]# vi /etc/my.cnf [mysqld] port= 4545 datadir= /home/ist/mysql
save and exit
Untuk Ubuntu
[root@DBA-Master ~]# vi /etc/mysql/mysql.conf.d/mysqld.cnf [mysqld] port=4545 datadir= /home/ist/mysql save and exit_
Langkah 3 - Mulai Ulang Layanan MySQL
Untuk CentOS
[root@DBA-Master ~]# service mysqld start
Untuk Ubuntu
[root@DBA-Master ~]# service mysql start_
Langkah 4 - Jalankan Skrip Keamanan [mysql_secure_installation]
[root@DBA-Master ~]# mysql_secure_installation Securing the MySQL server deployment. Enter password for user root:
The 'validate_password' plugin is installed on the server. The subsequent steps will run with the existing configuration of the plugin. Using existing password for root. Estimated strength of the password: 100 Change the password for root ? [[Press y|Y for Yes, any other key for No] : Y New password: Re-enter new password: Estimated strength of the password: 100 Do you wish to continue with the password provided?[Press y|Y for Yes, any other key for No] : Y By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Press y|Y for Yes, any other key for No] : Y Success. Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Press y|Y for Yes, any other key for No] : Y Success. By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Press y|Y for Yes, any other key for No] : Y - Dropping test database... Success. - Removing privileges on test database... Success. Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Press y|Y for Yes, any other key for No] : Y Success. All done!
[root@DBA-Master ~]# mysql -uroot -p
[root@DBA-Master ~]# service mysql stop0
Ini adalah Presentasi video untuk Mengubah Port default dan mengamankan mysql dengan mysql_secure_installation di MySQL
Ini termasuk klien GUI seperti meja kerja MySQL dan SQLyog, serta klien baris perintah mysql
Ubah port default MySQL
Anda dapat melihat dan mengedit port yang digunakan oleh server MySQL dengan memeriksa file konfigurasi yang digunakan oleh server MySQL Anda
Saat Anda menjalankan server dengan perintah start
, MySQL akan mencari file konfigurasi di lokasi berikut
/etc/my.cnf
/etc/mysql/my.cnf
/usr/local/mysql/etc/my.cnf
~/.my.cnf
Prioritas file-file di atas mengikuti urutannya. Artinya jika MySQL sudah menemukan file konfigurasi di lokasi /etc/my.cnf
, selebihnya akan diabaikan
Berikut prioritas lokasi untuk sistem operasi Windows
_1[mysqld] port = 3308 bind-address = 127.0.0.1 mysqlx-bind-address = 127.0.0.1
_2[mysqld] port = 3308 bind-address = 127.0.0.1 mysqlx-bind-address = 127.0.0.1
_3[mysqld] port = 3308 bind-address = 127.0.0.1 mysqlx-bind-address = 127.0.0.1
_4[mysqld] port = 3308 bind-address = 127.0.0.1 mysqlx-bind-address = 127.0.0.1
_5[mysqld] port = 3308 bind-address = 127.0.0.1 mysqlx-bind-address = 127.0.0.1
_6[mysqld] port = 3308 bind-address = 127.0.0.1 mysqlx-bind-address = 127.0.0.1
Sebagai alternatif, Anda dapat menyalurkan hasil dari perintah
[mysqld]
port = 3308
bind-address = 127.0.0.1
mysqlx-bind-address = 127.0.0.1
_7 ke perintah [mysqld]
port = 3308
bind-address = 127.0.0.1
mysqlx-bind-address = 127.0.0.1
8 dan [mysqld]
port = 3308
bind-address = 127.0.0.1
mysqlx-bind-address = 127.0.0.1
9 seperti yang ditunjukkan dalam jawaban StackOverflow iniAnda tidak perlu mencari file konfigurasi secara manual dengan trik ini
mysql --help | grep /my.cnf | xargs ls
ls: /etc/my.cnf: No such file or directory
ls: /etc/mysql/my.cnf: No such file or directory
ls: ~/.my.cnf: No such file or directory
/usr/local/etc/my.cnf
Hasil di atas menunjukkan bahwa file 3306
_0 di komputer lokal saya terletak di 3306
1
Setelah Anda menemukan file 3306
_2 [atau 3306
3 untuk Windows] maka Anda dapat menambahkan opsi 3306
4 ke bagian 3306
5 seperti yang ditunjukkan di bawah ini
[mysqld]
port = 3308
bind-address = 127.0.0.1
mysqlx-bind-address = 127.0.0.1
Jika tidak ada opsi 3306
4 yang ditentukan, maka MySQL akan default ke port 3306
Setelah Anda menentukan opsi 3306
_4, simpan perubahan Anda dan restart server MySQL Anda
Pada contoh di atas, server MySQL sekarang harus mendengarkan koneksi pada port 3306
9 bukan 3306
Jika Anda menggunakan klien GUI seperti MySQL Workbench, jangan lupa untuk mengubah port saat Anda perlu terhubung ke server