CentOS備忘録

CentOSの設定等に関するメモ

MySQLのインストール(目次)

 

MySQLのインストール(1/5)

0. OSのバージョンの確認
1. インストール
2. MySQLのバージョンの確認
3. 設定ファイルの確認
4. my.cnf のコピー
5. PATHの確認

 

MySQLのインストール(2/5)

6. データベースの初期化
7. データベースディレクトリの確認

 

MySQLのインストール(3/5)

 

8. mysqlの起動
9. MySQLへのログイン

 

MySQLのインストール(4/5)

10. 文字コードの確認
11. 文字コードの変更
12. mysql自動起動の設定

 

MySQLのインストール(5/5)

13. rootのパスワードの設定
14. アプリからの接続用ユーザの作成
15. 匿名ユーザの削除

 

 

参考サイト
MySQL http://www.mysql.com/

MySQLのインストール(5/5)

 

13. rootのパスワードの設定

# /usr/bin/mysqladmin -u root password 'your-password'
# /usr/bin/mysqladmin -u root -h your-domain.com password 'your-password'

 

ログインのテスト
# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.1.73-log 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>

 

ユーザーの一覧
mysql> select user,host,password from mysql.user;

 user  host  password 
 root  localhost  *ABCDEFGHIJKLMNOPQRSTUVWXYZ 
 root  your-domain.com  * ABCDEFGHIJKLMNOPQRSTUVWXYZ 
 root  127.0.0.1  
          localhost 
          your-domain.com 

5 rows in set (0.00 sec)

 

14. アプリからの接続用ユーザの作成

mysql> GRANT ALL ON *.* TO your-name@"localhost"IDENTIFIED BY "your-password";
Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql> select user,host,password from mysql.user;

 user  host  password 
 root  localhost  *ABCDEFGHIJKLMNOPQRSTUVWXYZ 
 root  your-domain.com  *ABCDEFGHIJKLMNOPQRSTUVWXYZ
 root  127.0.0.1 
          localhost 
          your-domain.com 
 your-name  localhost  *ABCDEFGHIJKLMNOPQRSTUVWXYZ

6 rows in set (0.00 sec)

 

15. 匿名ユーザの削除

mysql> DELETE FROM mysql.user WHERE User ='';
Query OK, 2 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql> select user,host,password from mysql.user;

 user  host  password 
 root  localhost  *ABCDEFGHIJKLMNOPQRSTUVWXYZ 
 root  your-domain.com  *ABCDEFGHIJKLMNOPQRSTUVWXYZ 
 root  127.0.0.1 
 your-name  localhost  *ABCDEFGHIJKLMNOPQRSTUVWXYZ 

4 rows in set (0.00 sec)

 

おしまい!

 

*上記 13 以降は、適宜、設定する。

 これで、MySQL を使う準備が完了!

 my.cnf をサンプル(最終形)として載せておく。

 

# cat /etc/my.cnf
# Example MySQL config file for medium systems.
#
# This is for a system with little memory (32M - 64M) where MySQL plays
# an important part, or systems up to 128M where MySQL is used together with
# other programs (such as a web server)
#
# MySQL programs look for option files in a set of
# locations which depend on the deployment platform.
# You can copy this option file to one of those
# locations. For information about these locations, see:
# http://dev.mysql.com/doc/mysql/en/option-files.html
#
# In this file, you can use all long options that a program supports.
# If you want to know which options a program supports, run the program
# with the "--help" option.

# The following options will be passed to all MySQL clients
[client]
#password = your_password
port = 3306
socket = /var/lib/mysql/mysql.sock

default-character-set=utf8

# Here follows entries for some specific programs

# The MySQL server
[mysqld]
port = 3306
socket = /var/lib/mysql/mysql.sock
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M

skip-character-set-client-handshake
character-set-server = utf8
collation-server = utf8_general_ci
init-connect = SET NAMES utf8

# Don't listen on a TCP/IP port at all. This can be a security enhancement,
# if all processes that need to connect to mysqld run on the same host.
# All interaction with mysqld must be made via Unix sockets or named pipes.
# Note that using this option without enabling named pipes on Windows
# (via the "enable-named-pipe" option) will render mysqld useless!
#
#skip-networking

# Replication Master Server (default)
# binary logging is required for replication
log-bin=mysql-bin

# binary logging format - mixed recommended
binlog_format=mixed

# required unique id between 1 and 2^32 - 1
# defaults to 1 if master-host is not set
# but will not function as a master if omitted
server-id = 1

# Replication Slave (comment out master section to use this)
#
# To configure this host as a replication slave, you can choose between
# two methods :
#
# 1) Use the CHANGE MASTER TO command (fully described in our manual) -
# the syntax is:
#
# CHANGE MASTER TO MASTER_HOST=<host>, MASTER_PORT=<port>,
# MASTER_USER=<user>, MASTER_PASSWORD=<password> ;
#
# where you replace <host>, <user>, <password> by quoted strings and
# <port> by the master's port number (3306 by default).
#
# Example:
#
# CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306,
# MASTER_USER='joe', MASTER_PASSWORD='secret';
#
# OR
#
# 2) Set the variables below. However, in case you choose this method, then
# start replication for the first time (even unsuccessfully, for example
# if you mistyped the password in master-password and the slave fails to
# connect), the slave will create a master.info file, and any later
# change in this file to the variables' values below will be ignored and
# overridden by the content of the master.info file, unless you shutdown
# the slave server, delete master.info and restart the slaver server.
# For that reason, you may want to leave the lines below untouched
# (commented) and instead use CHANGE MASTER TO (see above)
#
# required unique id between 2 and 2^32 - 1
# (and different from the master)
# defaults to 2 if master-host is set
# but will not function as a slave if omitted
#server-id = 2
#
# The replication master for this slave - required
#master-host = <hostname>
#
# The username the slave will use for authentication when connecting
# to the master - required
#master-user = <username>
#
# The password the slave will authenticate with when connecting to
# the master - required
#master-password = <password>
#
# The port the master is listening on.
# optional - defaults to 3306
#master-port = <port>
#
# binary logging - not required for slaves, but recommended
#log-bin=mysql-bin

# Uncomment the following if you are using InnoDB tables
#innodb_data_home_dir = /var/lib/mysql
#innodb_data_file_path = ibdata1:10M:autoextend
#innodb_log_group_home_dir = /var/lib/mysql
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
#innodb_buffer_pool_size = 16M
#innodb_additional_mem_pool_size = 2M
# Set .._log_file_size to 25 % of buffer pool size
#innodb_log_file_size = 5M
#innodb_log_buffer_size = 8M
#innodb_flush_log_at_trx_commit = 1
#innodb_lock_wait_timeout = 50

[mysqldump]
quick
max_allowed_packet = 16M

default-character-set=utf8

[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates

default-character-set=utf8

[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout

 

本当におしまい!

 

 

MySQLのインストール(4/5)

 

10. 文字コードの確認
mysql> show variables like 'char%';

 Variable_name      Value

 character_set_client  latin1 
 character_set_connection  latin1 
 character_set_database  latin1 
 character_set_filesystem  binary 
 character_set_results  latin1 
 character_set_server  latin1 
 character_set_system  utf8 
 character_sets_dir  /usr/share/mysql/charsets/ 

8 rows in set (0.00 sec)

 

11. 文字コードの変更

# vi /etc/my.cnf

   i

/// 以下を追記
[client]
   default-character-set=utf8
[mysqld]
   skip-character-set-client-handshake
   character-set-server = utf8
   collation-server = utf8_general_ci
   init-connect = SET NAMES utf8
[mysqldump]
   default-character-set=utf8
[mysql]
   default-character-set=utf8

///

   Esc

   :wq

# /etc/rc.d/init.d/mysqld restart
mysqld を停止中:            [ OK ]
mysqld を起動中:            [ OK ]

 

mysql> show variables like 'char%';

 Variable_name   Value 
 character_set_client  utf8 
 character_set_connection  utf8
 character_set_database  utf8 
 character_set_filesystem  binary 
 character_set_results  utf8 
 character_set_server  utf8 
 character_set_system  utf8 
 character_sets_dir  /usr/share/mysql/charsets/ 

8 rows in set (0.00 sec)

 

12. mysql自動起動の設定

# chkconfig --list mysqld
mysqld 0:off 1:off 2:off 3:off 4:off 5:off 6:off

# chkconfig mysqld on
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off

 

文字コードの変更をするための、my.cnf の記述内容は、

 注意が必要!

 必要があれば、テスト用のデータベースを作成し、漢字

 がきちんと表示されるか、どうかを確認すること!

 

MySQLのインストール(3/5)

 

8. mysqlの起動

# chown -R mysql:mysql /var/lib/mysql
# /etc/rc.d/init.d/mysqld start
mysqld を起動中:                         [ OK ]

 

9. MySQLへのログイン

# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.73-log 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>

 

*上記 8 で、# chown -R mysql:mysql /var/lib/mysql

    実行しないとハマる。

 こんな感じ。

# /etc/rc.d/init.d/mysqld start
MySQL Daemon failed to start.
mysqld を起動中:    [失敗]

 

エラーになったら、

# cat /var/lib/mysql/your-domain.com.err

で、エラーの内容を確認すること!

 

MySQLのインストール(2/5)

 

6. データベースの初期化

# vi /etc/my.cnf

 :%s/skip-locking/skip-external-locking/g

 Esc

   :wq

(注)my.cnf の skip-locking を skip-external-locking へ書き換える

 

# mysql_install_db
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 your-domain.com 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!

 

7. データベースディレクトリの確認
# cd /var/lib/mysql
# ls -la /var/lib/mysql
合計 23576
drwxr-xr-x 4 mysql mysql 4096 9月 21 12:14 2014 .
drwxr-xr-x 34 root root 4096 9月 21 07:54 2014 ..
-rw-rw---- 1 mysql mysql 5242880 9月 21 09:45 2014 ib_logfile0
-rw-rw---- 1 mysql mysql 5242880 9月 21 09:23 2014 ib_logfile1
-rw-rw---- 1 mysql mysql 10485760 9月 21 09:45 2014 ibdata1
drwx------ 2 root root 4096 9月 21 09:40 2014 mysql
-rw-rw---- 1 root root 19734 9月 21 09:40 2014 mysql-bin.000001
-rw-rw---- 1 root root 765307 9月 21 09:40 2014 mysql-bin.000002
-rw-rw---- 1 root root 19734 9月 21 09:52 2014 mysql-bin.000003
-rw-rw---- 1 root root 765307 9月 21 09:52 2014 mysql-bin.000004
-rw-rw---- 1 root root 19734 9月 21 12:06 2014 mysql-bin.000005
-rw-rw---- 1 root root 765307 9月 21 12:06 2014 mysql-bin.000006
-rw-rw---- 1 root root 19734 9月 21 12:14 2014 mysql-bin.000007
-rw-rw---- 1 root root 765307 9月 21 12:14 2014 mysql-bin.000008
-rw-rw---- 1 mysql mysql 152 9月 21 12:14 2014 mysql-bin.index
drwx------ 2 root root 4096 9月 21 08:39 2014 test
-rw-r----- 1 mysql root 3880 9月 21 09:45 2014 your-domain.com.err

 

*上記 6 で my.cnf の書き換えをしないとエラーになりハマる!

 こんな感じ・・・。

 # mysql_install_db
Installing MySQL system tables...
140921 12:06:54 [Warning] '--skip-locking' is deprecated and will be removed in a future release. Please use '--skip-external-locking' instead.
OK
Filling help tables...
140921 12:06:54 [Warning] '--skip-locking' is deprecated and will be removed in a future release. Please use '--skip-external-locking' instead.
OK

・・・・・

MySQLのインストール(1/5)

 

0. OSのバージョンの確認

# cat /etc/redhat-release
CentOS release 6.5 (Final)

 

1. インストール

# yum install mysql mysql-bench mysql-devel mysql-libs mysql-server

 

2. MySQLのバージョンの確認

# mysql --version
mysql Ver 14.14 Distrib 5.1.73, for redhat-linux-gnu (x86_64) using readline 5.1 

 

3. 設定ファイルの確認

# cd /usr/share/mysql
# ls

charsets my-innodb-heavy-4G.cnf
config.huge.ini my-large.cnf
config.medium.ini my-medium.cnf
config.small.ini my-small.cnf
czech mysql_fix_privilege_tables.sql
danish mysql_system_tables.sql
dutch mysql_system_tables_data.sql
english mysql_test_data_timezone.sql
errmsg.txt norwegian
estonian norwegian-ny
fill_help_tables.sql polish
french portuguese
german romanian
greek russian
hungarian serbian
italian slovak
japanese spanish
korean swedish
my-huge.cnf ukrainian

 

4. my.cnf のコピー

# cp /etc/my.cnf /etc/mysql_my.cnf.org    // オリジナルをコピー
# cp /usr/share/mysql/my-medium.cnf /etc/my.cnf // サンプルをコピー
cp: `/etc/my.cnf' を上書きしてもよろしいですか(yes/no)? yes

# ls -la my.cnf
-rw-r--r-- 1 root root 4673 9月 21 11:59 2014 my.cnf

 

5. PATHの確認
# echo $PATH
/usr/lib64/qt-.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/lapis/bin

# whereis mysql
mysql: /usr/bin/mysql /usr/lib64/mysql /usr/include/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz

# cd /usr/bin
# ls mysql*
mysql mysql_tzinfo_to_sql mysqld_multi
mysql_config mysql_upgrade mysqld_safe
mysql_convert_table_format mysql_waitpid mysqldump
mysql_find_rows mysql_zap mysqldumpslow
mysql_fix_extensions mysqlaccess mysqlhotcopy
mysql_fix_privilege_tables mysqladmin mysqlimport
mysql_install_db mysqlbinlog mysqlshow
mysql_secure_installation mysqlbug mysqlslap
mysql_setpermission mysqlcheck mysqltest

 

HTMLエディタ:Bluefish のインストール

 

1)インストール

# yum install -y bluefish

 

2)確認

# yum info bluefish

Installed Packages
Name : bluefish
Arch : i686
Version : 2.0.3
Release : 6.el6
Size : 1.2 M
Repo : installed
From repo : epel
Summary : GTK2 web development application for experienced users
URL : http://bluefish.openoffice.nl/
License : GPLv3+
Description : Bluefish is a powerful editor for experienced web
: designers and programmers. Bluefish supports many
: programming and markup languages, but it focuses on
: editing dynamic and interactive websites.

 

3)参考

see more >>> http://bluefish.openoffice.nl/index.html