หน้า 1 จากทั้งหมด 1

เทคนิคการตั้ง Root Password ของ MySQL

โพสต์โพสต์แล้ว: 17 มี.ค. 2017 10:57
โดย nuiz
บทความที่เกี่ยวข้อง
เปิดบริการ อบรม Elastix ด้วยคอร์สพิเศษ ให้ติดตั้ง คอนฟิกคล่อง ใช้งานคล่อง ได้ใน 3 วัน
เทคนิคการติดตั้ง phpMyAdmin บน FreePBX
เทคนิคการติดตั้ง FreePBX
เทคนิคการติดตั้ง Asterisk 13.14.0
เทคนิคการติดตั้ง Elastix 2.5
เทคนิคการแก้ไขปัญหา Ghost Calls บน IP Phone Yealink
ตรวจสอบว่า Asterisk กำลังใช้ Codecs อะไรอยู่และการปรับแต่ง
เทคนิคการตรวจสอบว่า Asterisk กำลังใช้ Codec อะไร และการปรับแต่ง Codecs
การแก้ไขรูปแบบการแสดงวันที่และเวลาใน Reports > CDR Reports

ใน FreePBX นะครับ โปรแกรมติดตั้งไม่ได้เซ็ต root password ของ MySQL มาให้ด้วย ทำให้เราเข้า MySQL ได้โดยไม่ต้องใช้ password ครับ มาดูตัวอย่างกัน
พิมพ์คำสั่ง mysql แล้วกด enter ก็จะเข้า prompt ของ MySQL ได้เลยครับ แบบนี้

[root@localhost ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 47
Server version: 5.1.73 Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql>

ผมเข้าจากเครื่องมันเองนะครับ แต่ลองเข้าจากเครื่องอื่นบ้างว่าจะเข้าได้มั๊ย

[root@fpbx-a ~]# mysql -h192.168.100.251
ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.100.251' (111)

เข้าไม่ได้ครับ เครื่องปลายทาง 192.168.100.251 มันบล๊อกไว้ ไม่ให้เข้า mysql ได้จากเครื่องอื่น

ผมจะแนะนำวิธีการเซ็ต root password ของ MySQL ครับ การตั้ง password นี้จะไม่มีผลอะไรต่อ FreePBX ครับ เพราะตอน FreePBX ติดต่อกับ MySQL มันใช้ user/pass ที่มันตั้งขึ้นมาตอนติดตั้งครับ เก็บไว้ในไฟล์ /etc/freepbx.conf ตัวอย่างครับ ผมก๊อบมาจากเครื่องผมเอง

<?php
$amp_conf['AMPDBUSER'] = 'freepbxuser';
$amp_conf['AMPDBPASS'] = 'ee2542275ca71d520176eec65c1e503d';
$amp_conf['AMPDBHOST'] = 'localhost';
$amp_conf['AMPDBNAME'] = 'asterisk';
$amp_conf['AMPDBENGINE'] = 'mysql';
$amp_conf['datasource'] = ''; //for sqlite3

require_once('/var/www/html/admin/bootstrap.php');
?>

วิธีการตั้ง root password ของ MySQL ครับ รันคำสั่ง mysql_secure_installation แล้วทำตามขั้นตอนที่เห็นครับ

[root@fpbx-a ~]# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root password? [Y/n] y ตอบ y
New password: พิมพ์พาสเวิร์ด
Re-enter new password: พิมพ์พาสเวอร์ดซ้ำ
Password updated successfully!
Reloading privilege tables..
... Success!

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? [Y/n] 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? [Y/n] 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? [Y/n] 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? [Y/n] y
... Success!

Cleaning up...

All done! If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!

เป็นอันว่าเราตั้ง root password ของ mysql เรียบร้อยแล้วครับ ต่อไปคือทดสอบครับว่ามันเวอร์ค
ลองไม่ระบุ user ก่อนครับ
[root@fpbx-a ~]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
เข้าไม่ได้ครับ งั้นลองแบบระบุ user ด้วย

[root@fpbx-a ~]# mysql -uroot -p
Enter password: ใส่พาสเวอร์ดตามที่ตั้งไว้
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 126
Server version: 5.1.73 Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql>

เข้าได้ครับ เวอร์คครับเวอร์ค