آموزش نصب MySQL در Ubuntu 18.04



 

در این آموزش نحوه نصب دیتابیس MySQL و بهینه سازی امنیتی رو در سیستم عامل Ubuntu 18.04 بصورت کوتاه و روان توضیح میدیم. دیتابیس MySQL یکی از دیتابیس های اوپن سورس رایج رابطه ای است که مورد استفاده Cms هایی مثل وردپرس ، جوملا ، مجنتو ، دروپال است ، در این مقاله نحوه نصب نسخه MySQL 5.7 رو آموزش میدیم.

 

قبل از نصب ابتدا یکبار سیستم عامل رو آپدیت میکنیم

sudo apt update
sudo apt upgrade

 

سپس با دستور زیر آخرین نسخه MySQL که 5.7 هست رو آغاز به نصب میکنیم که از repositories های اصلی ابونتو اقدام به نصب انجام میشه

sudo apt install mysql-server

 

سپس در مدت کوتاهی که نصب انجام میشد ، با دستور زیر میتونین وضعیت سرویس MySQL رو بررسی کنین

sudo systemctl status mysql

 

که خروجی زیر رو به شما میده

mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2019-02-08 02:05:27 CST; 2min 4s ago
 Main PID: 13853 (mysqld)
    Tasks: 27 (limit: 2321)
   CGroup: /system.slice/mysql.service
           └─13853 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid

همچنین با زدن دستور زیر سرویس mysql رو فعال میکنین که بعد از ریستارت یا بوت شدن مجدد سیستم عامل ، بصورت خودکار مجدد فعال بشه

sudo systemctl enable mysql

 

بهبود امنیت MySQL

برای بهبود امنیت دیتابیس MySQL نیاز به نصب و راه اندازی رمز برای یوزر root رو داریم که از طریق اسکریپت mysql_secure_installation باید این مورد رو پیاده سازی کنیم و رمز عبور رو میتونین اعتبار سنجی کنین ، برای همین ابتدا این اسکریپت رو با دستور زیر نصب میکنیم

sudo mysql_secure_installation

سپس خروجی زیر رو خواهد داد

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

 

بعد از شما درباره اعتبار سنجی رمز سوال میشود.

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No:

 

در واقع با استفاده از این پلاگین قدرت رمز عبور رو بررسی میکنه و به کاربر اجازه میده که رمزهای قوی رو انتخاب کنه که انتخاب یا عدم انتخاب رمز با کاربر هست.

There are three levels of password validation policy:

LOW Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG:

 

با انتخاب مراحل برای تغییر رمز جدید یوزر root و تایید ، مراحل زیر رو باید دنبال کنین

Please set the password for root here.

New password:

Re-enter new password:

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.

 

سپس تیبل های privilege باتوجه به تغییرات ، تغییر میکنن

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!

 

ورود به Mysql

برای ورود به به MySQL از دستوز زیر استفاده میکنیم

sudo mysql -u root -p

خروجی زیر رو خواهد داد

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.25-0ubuntu0.18.04.2 (Ubuntu)

Copyright (c) 2000, 2019, 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>

 

کانفیگ تنظیمات MySQL Database Server

برای تغییرات در تنظیمات دیتابیس ، بهینه سازی ، باید فایل زیر رو ویرایش کنین

sudo nano /etc/mysql/my.cnf

و بعد از اعمال تغییرات ، دیتابیس رو ریستارت کنین

sudo systemctl restart mysql

 

این آموزش نصب دیتابیس MySQL در سیستم عامل لینوکس ابونتو 18.04 بود.

 

آموزش نصب nodejs