総数:12 今日:1 昨日:0

もくじ

mysql-server パッケージのインストール

~$ sudo apt-get -y install mysql-server
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています                
状態情報を読み取っています... 完了
以下の追加パッケージがインストールされます:
  libaio1 libevent-core-2.1-6 libhtml-template-perl mysql-client-5.7 mysql-client-core-5.7 mysql-common mysql-server-5.7
  mysql-server-core-5.7
提案パッケージ:
  libipc-sharedcache-perl mailx tinyca
以下のパッケージが新たにインストールされます:
  libaio1 libevent-core-2.1-6 libhtml-template-perl mysql-client-5.7 mysql-client-core-5.7 mysql-common mysql-server
  mysql-server-5.7 mysql-server-core-5.7
アップグレード: 0 個、新規インストール: 9 個、削除: 0 個、保留: 9 個。
20.4 MB のアーカイブを取得する必要があります。
この操作後に追加で 160 MB のディスク容量が消費されます。
取得:1 http://jp.archive.ubuntu.com/ubuntu bionic/main amd64 mysql-common all 5.8+1.0.4 [7,308 B]
取得:2 http://jp.archive.ubuntu.com/ubuntu bionic/main amd64 libaio1 amd64 0.3.110-5 [6,448 B]
取得:3 http://jp.archive.ubuntu.com/ubuntu bionic-updates/main amd64 mysql-client-core-5.7 amd64 5.7.23-0ubuntu0.18.04.1 [6,985 kB]
取得:4 http://jp.archive.ubuntu.com/ubuntu bionic-updates/main amd64 mysql-client-5.7 amd64 5.7.23-0ubuntu0.18.04.1 [2,312 kB]
取得:5 http://jp.archive.ubuntu.com/ubuntu bionic-updates/main amd64 mysql-server-core-5.7 amd64 5.7.23-0ubuntu0.18.04.1 [7,777 kB]
取得:6 http://jp.archive.ubuntu.com/ubuntu bionic/main amd64 libevent-core-2.1-6 amd64 2.1.8-stable-4build1 [85.9 kB]
取得:7 http://jp.archive.ubuntu.com/ubuntu bionic-updates/main amd64 mysql-server-5.7 amd64 5.7.23-0ubuntu0.18.04.1 [3,194 kB]
取得:8 http://jp.archive.ubuntu.com/ubuntu bionic/main amd64 libhtml-template-perl all 2.97-1 [59.0 kB]
取得:9 http://jp.archive.ubuntu.com/ubuntu bionic-updates/main amd64 mysql-server all 5.7.23-0ubuntu0.18.04.1 [9,940 B]
20.4 MB を 3秒 で取得しました (6,866 kB/s)
パッケージを事前設定しています ...
以前に未選択のパッケージ mysql-common を選択しています。
(データベースを読み込んでいます ... 現在 171019 個のファイルとディレクトリがインストールされています。)
.../0-mysql-common_5.8+1.0.4_all.deb を展開する準備をしています ...
mysql-common (5.8+1.0.4) を展開しています...
以前に未選択のパッケージ libaio1:amd64 を選択しています。
.../1-libaio1_0.3.110-5_amd64.deb を展開する準備をしています ...
libaio1:amd64 (0.3.110-5) を展開しています...
以前に未選択のパッケージ mysql-client-core-5.7 を選択しています。
.../2-mysql-client-core-5.7_5.7.23-0ubuntu0.18.04.1_amd64.deb を展開する準備をしています ...
mysql-client-core-5.7 (5.7.23-0ubuntu0.18.04.1) を展開しています...
以前に未選択のパッケージ mysql-client-5.7 を選択しています。
.../3-mysql-client-5.7_5.7.23-0ubuntu0.18.04.1_amd64.deb を展開する準備をしています ...
mysql-client-5.7 (5.7.23-0ubuntu0.18.04.1) を展開しています...
以前に未選択のパッケージ mysql-server-core-5.7 を選択しています。
.../4-mysql-server-core-5.7_5.7.23-0ubuntu0.18.04.1_amd64.deb を展開する準備をしています ...
mysql-server-core-5.7 (5.7.23-0ubuntu0.18.04.1) を展開しています...
以前に未選択のパッケージ libevent-core-2.1-6:amd64 を選択しています。
.../5-libevent-core-2.1-6_2.1.8-stable-4build1_amd64.deb を展開する準備をしています ...
libevent-core-2.1-6:amd64 (2.1.8-stable-4build1) を展開しています...
mysql-common (5.8+1.0.4) を設定しています ...
update-alternatives: /etc/mysql/my.cnf (my.cnf) を提供するために自動モードで /etc/mysql/my.cnf.fallback を使います
以前に未選択のパッケージ mysql-server-5.7 を選択しています。
(データベースを読み込んでいます ... 現在 171187 個のファイルとディレクトリがインストールされています。)
.../mysql-server-5.7_5.7.23-0ubuntu0.18.04.1_amd64.deb を展開する準備をしています ...
mysql-server-5.7 (5.7.23-0ubuntu0.18.04.1) を展開しています...
以前に未選択のパッケージ libhtml-template-perl を選択しています。
.../libhtml-template-perl_2.97-1_all.deb を展開する準備をしています ...
libhtml-template-perl (2.97-1) を展開しています...
以前に未選択のパッケージ mysql-server を選択しています。
.../mysql-server_5.7.23-0ubuntu0.18.04.1_all.deb を展開する準備をしています ...
mysql-server (5.7.23-0ubuntu0.18.04.1) を展開しています...
libevent-core-2.1-6:amd64 (2.1.8-stable-4build1) を設定しています ...
libhtml-template-perl (2.97-1) を設定しています ...
ureadahead (0.100.0-20) のトリガを処理しています ...
ureadahead will be reprofiled on next reboot
libc-bin (2.27-3ubuntu1) のトリガを処理しています ...
libaio1:amd64 (0.3.110-5) を設定しています ...
systemd (237-3ubuntu10.3) のトリガを処理しています ...
man-db (2.8.3-2) のトリガを処理しています ...
mysql-client-core-5.7 (5.7.23-0ubuntu0.18.04.1) を設定しています ...
mysql-server-core-5.7 (5.7.23-0ubuntu0.18.04.1) を設定しています ...
mysql-client-5.7 (5.7.23-0ubuntu0.18.04.1) を設定しています ...
mysql-server-5.7 (5.7.23-0ubuntu0.18.04.1) を設定しています ...
update-alternatives: /etc/mysql/my.cnf (my.cnf) を提供するために自動モードで /etc/mysql/mysql.cnf を使います
Renaming removed key_buffer and myisam-recover options (if present)
Created symlink /etc/systemd/system/multi-user.target.wants/mysql.service → /lib/systemd/system/mysql.service.
mysql-server (5.7.23-0ubuntu0.18.04.1) を設定しています ...
libc-bin (2.27-3ubuntu1) のトリガを処理しています ...
ureadahead (0.100.0-20) のトリガを処理しています ...
systemd (237-3ubuntu10.3) のトリガを処理しています ...

php-mysql パッケージのインストール

~$ sudo apt-get -y install php-mysql
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています                
状態情報を読み取っています... 完了
以下の追加パッケージがインストールされます:
  php-common php7.0-common php7.0-mysql
以下のパッケージが新たにインストールされます:
  php-common php-mysql php7.0-common php7.0-mysql
アップグレード: 0 個、新規インストール: 4 個、削除: 0 個、保留: 134 個。
977 kB のアーカイブを取得する必要があります。
この操作後に追加で 5,275 kB のディスク容量が消費されます。
取得:1 http://jp.archive.ubuntu.com/ubuntu xenial-updates/main amd64 php-common all 1:35ubuntu6.1 [10.8 kB]
取得:2 http://jp.archive.ubuntu.com/ubuntu xenial-updates/main amd64 php7.0-common amd64 7.0.28-0ubuntu0.16.04.1 [840 kB]
取得:3 http://jp.archive.ubuntu.com/ubuntu xenial-updates/main amd64 php7.0-mysql amd64 7.0.28-0ubuntu0.16.04.1 [124 kB]
取得:4 http://jp.archive.ubuntu.com/ubuntu xenial-updates/main amd64 php-mysql all 1:7.0+35ubuntu6.1 [1,928 B]
977 kB を 0秒 で取得しました (3,500 kB/s)
以前に未選択のパッケージ php-common を選択しています。
(データベースを読み込んでいます ... 現在 186076 個のファイルとディレクトリがインストールされています。)
.../php-common_1%3a35ubuntu6.1_all.deb を展開する準備をしています ...
php-common (1:35ubuntu6.1) を展開しています...
以前に未選択のパッケージ php7.0-common を選択しています。
.../php7.0-common_7.0.28-0ubuntu0.16.04.1_amd64.deb を展開する準備をしています ...
php7.0-common (7.0.28-0ubuntu0.16.04.1) を展開しています...
以前に未選択のパッケージ php7.0-mysql を選択しています。
.../php7.0-mysql_7.0.28-0ubuntu0.16.04.1_amd64.deb を展開する準備をしています ...
php7.0-mysql (7.0.28-0ubuntu0.16.04.1) を展開しています...
以前に未選択のパッケージ php-mysql を選択しています。
.../php-mysql_1%3a7.0+35ubuntu6.1_all.deb を展開する準備をしています ...
php-mysql (1:7.0+35ubuntu6.1) を展開しています...
php-common (1:35ubuntu6.1) を設定しています ...
php7.0-common (7.0.28-0ubuntu0.16.04.1) を設定しています ...

Creating config file /etc/php/7.0/mods-available/calendar.ini with new version

Creating config file /etc/php/7.0/mods-available/ctype.ini with new version

Creating config file /etc/php/7.0/mods-available/exif.ini with new version

Creating config file /etc/php/7.0/mods-available/fileinfo.ini with new version

Creating config file /etc/php/7.0/mods-available/ftp.ini with new version

Creating config file /etc/php/7.0/mods-available/gettext.ini with new version

Creating config file /etc/php/7.0/mods-available/iconv.ini with new version

Creating config file /etc/php/7.0/mods-available/pdo.ini with new version

Creating config file /etc/php/7.0/mods-available/phar.ini with new version

Creating config file /etc/php/7.0/mods-available/posix.ini with new version

Creating config file /etc/php/7.0/mods-available/shmop.ini with new version

Creating config file /etc/php/7.0/mods-available/sockets.ini with new version

Creating config file /etc/php/7.0/mods-available/sysvmsg.ini with new version

Creating config file /etc/php/7.0/mods-available/sysvsem.ini with new version

Creating config file /etc/php/7.0/mods-available/sysvshm.ini with new version

Creating config file /etc/php/7.0/mods-available/tokenizer.ini with new version
php7.0-mysql (7.0.28-0ubuntu0.16.04.1) を設定しています ...

Creating config file /etc/php/7.0/mods-available/mysqlnd.ini with new version

Creating config file /etc/php/7.0/mods-available/mysqli.ini with new version

Creating config file /etc/php/7.0/mods-available/pdo_mysql.ini with new version
php-mysql (1:7.0+35ubuntu6.1) を設定しています ...

mysql-client パッケージのインストール

~$ sudo apt-get -y install mysql-client
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています                
状態情報を読み取っています... 完了
以下のパッケージが新たにインストールされます:
  mysql-client
アップグレード: 0 個、新規インストール: 1 個、削除: 0 個、保留: 134 個。
10.0 kB のアーカイブを取得する必要があります。
この操作後に追加で 110 kB のディスク容量が消費されます。
取得:1 http://jp.archive.ubuntu.com/ubuntu xenial-updates/main amd64 mysql-client all 5.7.22-0ubuntu0.16.04.1 [10.0 kB]
10.0 kB を 0秒 で取得しました (84.9 kB/s)
以前に未選択のパッケージ mysql-client を選択しています。
(データベースを読み込んでいます ... 現在 186166 個のファイルとディレクトリがインストールされています。)
.../mysql-client_5.7.22-0ubuntu0.16.04.1_all.deb を展開する準備をしています ...
mysql-client (5.7.22-0ubuntu0.16.04.1) を展開しています...
mysql-client (5.7.22-0ubuntu0.16.04.1) を設定しています ...

MySQL環境のセキュア化

参考URL http://www.cyberciti.biz/faq/howto-install-mysql-on-ubuntu-linux-16-04/

Run mysql_secure_installation to secure your installation

For all production server you must run the following command:

$ sudo mysql_secure_installation
Securing the MySQL server deployment.

Enter password for user root: 

パスワードを入力する。

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:

enterキーを押す。

Using existing password for root.
Change the password for root ? ((Press y|Y for Yes, any other key for No) :

enterキーを押す。

 ... skipping.
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) : 

enterキーを押す。

 ... skipping.
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.
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! 

QA about mysql5.7

How do I use MySQL server?

To log in as the root user, type:

$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.22-0ubuntu0.16.04.1 (Ubuntu)

Copyright (c) 2000, 2018, 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> exit
Bye

How do I create a new MySQL server database and user account?

The sql syntax is as follows to create a new mysql database and setup password:

mysql> create database <DATABASE-NAME>;
mysql> grant all on <DATABASE-NAME>.* to '<DATABASE-USERNAME>' identified by 'DATABASE-PASSWORD';
mysql> quit;

Now, try to log in as vivek user, enter:

$ mysql -u <DATABASE-USERNAME> -p <DATABASE-NAME>

How do I start MySQL server?

$ sudo systemctl start mysql

How do I stop MySQL server?

$ sudo systemctl stop mysql

How do I restart MySQL server?

$ sudo systemctl restart mysql

How do I find out if MySQL running/active?

$ sudo systemctl status mysql.service
● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: active (running) since 金 2018-05-04 17:27:36 JST; 19min ago
 Main PID: 5021 (mysqld)
   CGroup: /system.slice/mysql.service
           └─5021 /usr/sbin/mysqld

 5月 04 17:27:35 ubdt16044 systemd[1]: Starting MySQL Community Server...
 5月 04 17:27:36 ubdt16044 systemd[1]: Started MySQL Community Server.

How do I reset the mysql root account password?

$ sudo dpkg-reconfigure mysql-server-5.7

A note about MySQL server configuration

You may edit the /etc/mysql/my.cnf file to configure the basic settings
such as TCP/IP port, IP address binding, and other options.
However, The MySQL database server configuration file on the Ubuntu 16.04 LTS is
located at

/etc/mysql/mysql.conf.d/mysqld.cnf

and one can edit using a text editor such as gvim:

$ sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf
$ sudo systemctl restart mysql.service

データベース ディレクトリ構造の生成

参考URL https://dev.mysql.com/doc/refman/5.7/en/data-directory-initialization-mysqld.html

mysqld設定ファイルをみてデータの所在を知る

~$ cat /etc/mysql/mysql.conf.d/mysqld.cnf
#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
# 
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

# This will be passed to all mysql clients
# It has been reported that passwords should be enclosed with ticks/quotes
# escpecially if they contain "#" chars...
# Remember to edit /etc/mysql/debian.cnf when changing the socket location.

# Here is entries for some specific programs
# The following values assume you have at least 32M ram

[mysqld_safe]
socket		= /var/run/mysqld/mysqld.sock
nice		= 0

[mysqld]
#
# * Basic Settings
#
user		= mysql
pid-file	= /var/run/mysqld/mysqld.pid
socket		= /var/run/mysqld/mysqld.sock
port		= 3306
basedir		= /usr
datadir		= /var/lib/mysql
tmpdir		= /tmp
lc-messages-dir	= /usr/share/mysql
skip-external-locking
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address		= 127.0.0.1
#
# * Fine Tuning
#
key_buffer_size		= 16M
max_allowed_packet	= 16M
thread_stack		= 192K
thread_cache_size       = 8
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover-options  = BACKUP
#max_connections        = 100
#table_cache            = 64
#thread_concurrency     = 10
#
# * Query Cache Configuration
#
query_cache_limit	= 1M
query_cache_size        = 16M
#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
# As of 5.1 you can enable the log at runtime!
#general_log_file        = /var/log/mysql/mysql.log
#general_log             = 1
#
# Error log - should be very few entries.
#
log_error = /var/log/mysql/error.log
#
# Here you can see queries with especially long duration
#log_slow_queries	= /var/log/mysql/mysql-slow.log
#long_query_time = 2
#log-queries-not-using-indexes
#
# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
#       other settings you may need to change.
#server-id		= 1
#log_bin			= /var/log/mysql/mysql-bin.log
expire_logs_days	= 10
max_binlog_size   = 100M
#binlog_do_db		= include_database_name
#binlog_ignore_db	= include_database_name
#
# * InnoDB
#
# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
# Read the manual for more InnoDB related options. There are many!
#
# * Security Features
#
# Read the manual, too, if you want chroot!
# chroot = /var/lib/mysql/
#
# For generating SSL certificates I recommend the OpenSSL GUI "tinyca".
#
# ssl-ca=/etc/mysql/cacert.pem
# ssl-cert=/etc/mysql/server-cert.pem
# ssl-key=/etc/mysql/server-key.pem

データはここだ

datadir		= /var/lib/mysql

mysqldのベースディレクトリはここ

basedir		= /usr

ちなみにmysqldの所在はここ

~$ which mysqld
/usr/sbin/mysqld

次は


トップ   一覧 単語検索 最終更新   ヘルプ   最終更新のRSS