MySql Kurulumu
CentOS 7'de Mysql 5.6 kurulumu
Bu makalede Mysql Community sürümü kurup yapılandıracağız.
Dosyaları indirmek için sunucuda bir data dizini oluşturup bu dizine geçiş yapıyoruz.
mkdir ~/data
cd ~/data
CentOS 7 üzerinde varsayılan olarak MariaDB repoları gelmektedir. yum -y install mysql
dediğinizde MariaDB'yi kurmuş olursunuz bu yüzden Mysql Community Server reposunu sunucuya yüklememiz gerekiyor. Mysql Community Reposu için gerekli RPM dosyasını wget
ile sunucumuza indirelim wget sunucuda yok ise yum -y install wget
diyerek sunucuya yükleyebilirsiniz.
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
Sunucuya dosyayı indirdik, şimdi RPM dosyasını sunucuya yükleyim. Sunucuya herhangi bir RPM yüklemek için rpm -ivh dosya-ismi
komutunu kullanmanız yeterlidir.
rpm -ivh mysql-community-release-el7-5.noarch.rpm
Mysql 5.6 için gerekli repolar sunucuya yüklediğimiz RPM sayesinde sunucuda oluştu. Repoları kontrol etmek için CentOS 7'de repoların bulunduğu dizin (/etc/yum.repos.d) altında mysql repoları var mı kontrol edelim.
ls -l /etc/yum.repos.d/mysql-community*
Ekran çıktısı aşağıdaki gibi olmalıdır.
[[email protected] ~]# ls -l /etc/yum.repos.d/mysql-community*
-rw-r--r--. 1 root root 1209 Jan 29 2014 /etc/yum.repos.d/mysql-community.repo
-rw-r--r--. 1 root root 1060 Jan 29 2014 /etc/yum.repos.d/mysql-community-source.repo
Repolarımız olduğuna göre mysql sunucusunu kurabiliriz. Kurulum için aşağıdaki komutu kullanın.
yum -y install mysql-server
Mysql'i başlatalım.
systemctl start mysqld
Mysql çalışıyor mu kontrol edelim.
systemctl status mysqld
Ekra görüntüsü aşağıdaki gibi olmalıdır.
Mysql'i daha güvenli hale getirmek için aşağıdaki komutu kullanıp sırasıyla adımları izleyelim.
- Önce root şifresi soracak daha belirlemedimiz için birşey yazmadan Enter tuşuna basın.
- Root şifresini belirmek isteyip istemidiğinizi soracak Y harifini yazıp Enter'a baın.
- Root şifresini yazıp Enter'a basın.
- Root şifresini tekrar yazıp Enter'a basın.
- anonymous kullanıcısını sileyim mi? Y harfine basıp Enter'a basın.
- Mysql sunucusuna uzaktan bağlantı kapatılsın mı? Y harfine basıp Enter'a basın.
- Test veritabanını ve erişimlerini sileyim mi? Y harfine basıp Enter'a basın.
- Tablo ayrıcalıklarını yeniden yükle? Y harfine basıp Enter'a basın.
mysql_secure_installation
Ekran çıktısı aşağıdaki gibi olmalıdır.
[[email protected] data]# 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
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...
- 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!
All done! If you've completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
Cleaning up...
Mysql artık daha güvenli.
Mysql'i yeniden başlatalım.
systemctl restart mysqld
- Mysql'de komut satırına geçmek?
- Mysql'de veritabanı oluşturma?
- Mysql'de bir kullanıcı oluşturma?
- Mysql'de bir kullanıcıya bir veritabanı ile ilgili tüm yetkileri verme?
Bu soruların cevapları için aşağıdaki komutları kullanabilirsiniz.
- Mysql'e komut satıra yönetici olarak geçmek için
mysql -u root -ppassword
komutulu kullanıyoruz. - Yeni bir veritabanı için
create database veritabani-adi default character set utf8;
- Yeni bir kullanıcı oluşturmak için
create user 'kullanaci-adi'@'localhost' identified by 'password';
- Tüm yetkileri vermek için
grant all on testdb.* TO 'testuser'@'localhost';
Aşağıdaki örnekte mysql'de root olarak otorum açma, veritanı oluşturma, kullanıcı oluşturma ve bir kullanıcıya bir veritanı için tüm yetkileri vermeyi bulabilirsiniz.
[[email protected] data]# mysql -u root -ppassword
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 15
Server version: 5.6.35 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, 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> create database testdb default character set utf8;
Query OK, 1 row affected (0.00 sec)
mysql> create user 'testuser'@'localhost' identified by 'password';
Query OK, 0 rows affected (0.00 sec)
mysql> grant all on testdb.* TO 'testuser'@'localhost';
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye
Oluşturduğumu kullanıcı ile mysql komut satırına giriş yapıp veritabanımız oluşmuş mu görelim.
[[email protected] data]# mysql -u testuser -ppass
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 17
Server version: 5.6.35 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, 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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| testdb |
+--------------------+
2 rows in set (0.00 sec)
mysql>
Mysql Community Server https://dev.mysql.com/downloads/mysql/ ↩