MySQL database installation and database creation

1. Download the installation package
CD
mkdir downloads
CD downloads
wget -C -m-MySQL 5.7.20 -O-Linux-glibc2.12-x86_64.tar.gz https://cdn.mysql.com//Downloads/MySQL-5.7 /mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz

2. Create users and groups
groupadd MySQL
useradd -g MySQL -s / sbin / nologin MySQL

3. Extract the specified directory
CD
CD downloads
the tar--zxvf MySQL 5.7.20-Linux-glibc2.12-x86_64.tar.gz -C / usr / local
CD / usr / local /
LN MySQL -s-5.7.20- linux-glibc2.12-x86_64 mysql

4.配置PATH
echo “export PATH=$PATH:/usr/local/mysql/bin” >> /etc/profile
source /etc/profile

The database directory schema
file type instance 3306 soft
data datadir / usr / local / mysql / data / data / mysql / data
parameter file my.cnf /usr/local/mysql/etc/my.cnf
error log log-error / usr / local / mysql / log / mysql_error.log
binary logging log-bin / usr / local / mysql / binlogs / mysql-bin / data / mysql / binlogs / mysql-bin
slow query log slow_query_log_file / usr / local / mysql / log /mysql_slow_query.log
socket socket file /usr/local/mysql/run/mysql.sock
pid file /usr/local/mysql/run/mysql.pid
Note: In view data and the binary log is relatively large, need soft

创建目录并赋权给MySQL用户
mkdir -p /data/mysql/{data,binlogs,log,etc,run}
ln -s /data/mysql/data /usr/local/mysql/data
ln -s /data/mysql/binlogs /usr/local/mysql/binlogs
ln -s /data/mysql/log /usr/local/mysql/log
ln -s /data/mysql/etc /usr/local/mysql/etc
ln -s /data/mysql/run /usr/local/mysql/run
chown -R mysql.mysql /data/mysql/
chown -R mysql.mysql /usr/local/mysql/{data,binlogs,log,etc,run}

May only log data directory and directory binary soft
mkdir -p / usr / local / MySQL / {log, etc, RUN}
mkdir -p / Data / MySQL / {Data, binlogs}
LN -s / Data / MySQL / Data / usr / local / MySQL / Data
LN -s / Data / MySQL / binlogs / usr / local / MySQL / binlogs
chown -R & lt mysql.mysql / usr / local / MySQL / {Data, binlogs, log, etc,} RUN
chown -R mysql.mysql / data / mysql

6. my.cnf configuration parameter file
delete system comes my.cnf
RM -f /etc/my.cnf

Create a my.cnf file in / usr / local / mysql / etc / down, add the following parameters, other parameters as required
vi /usr/local/mysql/etc/my.cnf

[client]
port = 3306
socket = /usr/local/mysql/run/mysql.sock

[mysqld]
port = 3306
socket = /usr/local/mysql/run/mysql.sock
pid_file = /usr/local/mysql/run/mysql.pid
datadir = /usr/local/mysql/data
default_storage_engine = InnoDB
max_allowed_packet = 512M
max_connections = 2048
open_files_limit = 65535

skip-name-resolve
lower_case_table_names=1

character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect=’SET NAMES utf8mb4′

innodb_buffer_pool_size = 1024M
innodb_log_file_size = 2048M
innodb_file_per_table = 1
innodb_flush_log_at_trx_commit = 0

key_buffer_size = 64M

log-error = /usr/local/mysql/log/mysql_error.log
log-bin = /usr/local/mysql/binlogs/mysql-bin
slow_query_log = 1
slow_query_log_file = /usr/local/mysql/log/mysql_slow_query.log
long_query_time = 5

tmp_table_size = 32M
max_heap_table_size = 32M
query_cache_type = 0
query_cache_size = 0

server-id=1

7. Database Initialization
performed:
mysqld MySQL -basedir -initialize -user = = / usr / local / MySQL -datadir = / usr / local / MySQL / Data

In the log file will prompt a temporary password, record the password
grep 'the Temporary password' /usr/local/mysql/log/mysql_error.log
[Note] A IS Generated the Temporary password for root @ localhost: password

8.生成ssl
mysql_ssl_rsa_setup –basedir=/usr/local/mysql –datadir=/usr/local/mysql/data/

9. Set Item Start
the CentOS. 6
CD / usr / local / MySQL
CP-Support Files / /etc/init.d/mysql.server the mysql.server
the chkconfig -add the mysql.server
the chkconfig the mysql.server ON
the chkconfig -list

. 7 the CentOS
CD / usr / lib / systemd / System
Touch mysqld.service
edits follows

we /usr/lib/systemd/system/mysqld.service

# Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# systemd service file for MySQL forking server
#

[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target

[Install]
WantedBy=multi-user.target

[Service]
User=mysql
Group=mysql

Type=forking

PIDFile=/usr/local/mysql/run/mysqld.pid

# Disable service start and stop timeout logic of systemd for mysqld service.
TimeoutSec=0

# Execute pre and post scripts as root
PermissionsStartOnly=true

# Needed to create system tables
#ExecStartPre=/usr/bin/mysqld_pre_systemd

# Start main service
ExecStart=/usr/local/mysql/bin/mysqld –daemonize –pid-file=/usr/local/mysql/run/mysqld.pid $MYSQLD_OPTS
# other: ExecStart=/usr/local/mysql/bin/mysqld –defaults-file=/usr/local/mysql/etc/my.cnf

# Use this to switch malloc implementation
EnvironmentFile=-/etc/sysconfig/mysql

# Sets open_files_limit
LimitNOFILE = 65535

Restart=on-failure

RestartPreventExitStatus=1

PrivateTmp=false

加载
systemctl daemon-reload
systemctl enable mysqld.service
systemctl is-enabled mysqld

10. Start MySQL
systemctl Start mysqld

11. Securing the Initial MySQL Accounts
reset the password (last step has been reset after this time can be ignored)
delete anonymous users
turn off the root user remote login
delete the test database

$ /usr/local/mysql/bin/mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root:

The existing password for the user account root has expired. Please set a new password.

New password:

Re-enter new 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: Y

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: 2
Using existing password for root.

Estimated strength of the password: 100
Change the password for root ? ((Press y|Y for Yes, any other key for No) : N

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

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!

12.Populating the Time Zone Tables
time zone information to import
$ mysql_tzinfo_to_sql / usr / share / zoneinfo | mysql -u root -p mysql

13.测试
#mysqladmin version -uroot -p
Enter password:
mysqladmin Ver 8.42 Distrib 5.7.20, for linux-glibc2.5 on x86_64
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.

Server version 5.7.20-log
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /usr/local/mysql/run/mysql.sock
Uptime: 4 min 0 sec

Threads: 1 Questions: 8681 Slow queries: 0 Opens: 122 Flush tables: 1 Open tables: 103 Queries per second avg: 36.170

Check the variable
$ mysqladmin variables -uroot -p

14.开放3306端口
##Add
firewall-cmd –permanent –zone=public –add-port=3306/tcp
firewall-cmd –permanent –zone=public –add-port=3306/udp
##Reload
firewall-cmd –reload

## to check whether the entry into force of
firewall-cmd -zone = public -query- port = 3306 / tcp

## lists all open ports
firewall-cmd -list-all

15.登陆创建数据库
mysql -uroot -p
passwd
show databases;
create database football default character set utf8 collate utf8_general_ci;
use information_schema;
grant all on football.* to socer@”%” identified by “Abc1234!”;
grant select on *.* to socer@”%” identified by “Abc1234!”;

FQ: Database creation error resolution time function
1, Error Code: 1227. Access denied; you need (AT Least One of) at The SUPER Privilege (S) Operation for the this
- to see if the open function to create functions
show variables like '% func % ';
- a function to create the opening function
SET = Global log_bin_trust_function_creators. 1;
the FLUSH PRIVILEGES

2、[Err] 1055 – Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column ‘information_schema.PROFILING.SEQ’ which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_gr

. a using a find command to find the file named my.cnf
# find / -name my.cnf
b using the vi command to edit the file, add the following statement:.
vi /data/mysql/etc/my.cnf
sql_mode = 'STRICT_TRANS_TABLES, NO_ZERO_IN_DATE, NO_ZERO_DATE, ERROR_FOR_DIVISION_BY_ZERO, NO_AUTO_CREATE_USER, NO_ENGINE_SUBSTITUTION '
final portion of the code as follows:
Character-Server-SET = utf8mb4
lower_case_table_names. 1 =

skip-host-cache
skip-name-resolve

sql_mode=’STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION’

[client]
default-character-set=utf8mb4

Guess you like

Origin www.cnblogs.com/zutanhongke/p/12168472.html