Linux環境MySQLのインストールと構成

4030 ワード

1.MySQL-Server(yum)のインストール
[root@localhost ~]# yum list | grep mysql

 
[root@localhost ~]# yum install mysql-server.x86_64 

 
2.構成:
表名の大文字と小文字を区別しない構成
ファイルを開く
[root@localhost ~]# vi /etc/my.cnf

変更
[mysqld]
lower_case_table_names=1

再起動
[root@localhost ~]# service mysqld restart 
Stopping mysqld:                                           [  OK  ]
Starting mysqld:                                           [  OK  ]

 
3.データベースの起動
[root@localhost ~]# service mysqld start

 
[root@localhost ~]# service mysqld start 
Initializing MySQL database:  Installing MySQL system tables...
OK
Filling help tables...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h localhost.localdomain password 'new-password'

Alternatively you can run:
/usr/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd /usr/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /usr/bin/mysqlbug script!

                                                           [  OK  ]
Starting mysqld:                                           [  OK  ]

 
4.rootユーザーパスワードの変更
[root@localhost ~]# mysqladmin -u root password 'new-password'

 
 
[root@localhost ~]# mysqladmin -u root -h localhost.localdomain password 'new-password' -p

 
 
5.データベースへの登録
[root@localhost etc]# mysql -u root -p

 
 
mysql> use mysql;

 
mysql> select host,user,password from user;
+-----------------------+------+-------------------------------------------+
| host                  | user | password                                  |
+-----------------------+------+-------------------------------------------+
| localhost             | root | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
| localhost.localdomain | root |                                           |
| 127.0.0.1             | root |                                           |
| localhost             |      |                                           |
| localhost.localdomain |      |                                           |
+-----------------------+------+-------------------------------------------+
5 rows in set (0.00 sec)

 
 
6.データベースの作成
CREATE DATABASE `YourDBName`CHARACTER SET utf8 ;

 
7.ユーザーの作成
INSERT INTO USER(HOST,USER,PASSWORD) VALUES('%','YourDBUsername',PASSWORD('YourDBPassword'));  
FLUSH PRIVILEGES;

 
 8. ユーザー権限(クエリー、更新、変更、削除...)
 
GRANT ALL ON YourDBName.* TO YourDBUsername@'%';
FLUSH PRIVILEGES; 

 
 
9.セキュリティ上の考慮事項(ローカルエリアネットワークアクセス、3306ポート、ファイアウォール設定、外部ネットワーク使用制限ユーザーアクセスのみ)