# lsb_release -a
LSB Version: :core-4.1-amd64:core-4.1-noarch
Distributor ID: CentOS
Description: CentOS Linux release 7.5.1804 (Core)
Release: 7.5.1804
Codename: Core
2.下载MySQL
# cd /home/install-files
# wget http://ftp.kaist.ac.kr/mysql/Downloads/MySQL-5.7/mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
3.解压修改安装名称
# tar zxvf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
# cd /usr/local/
# ls
aegis bin etc games include lib lib64 libexec mysql-5.7.23-linux-glibc2.12-x86_64 sbin share src
# mv mysql-5.7.23-linux-glibc2.12-x86_64/ mysql
# ls
aegis bin etc games include lib lib64 libexec mysql sbin share src
# cd /usr/local/mysql/bin
innochecksum myisamchk mysql_client_test_embedded mysql_install_db mysql_tzinfo_to_sql mysqlcheck mysqld_safe mysqlpump mysqlxtest resolveip
lz4_decompress myisamlog mysql_config mysql_plugin mysql_upgrade mysqld mysqldump mysqlshow perror zlib_decompress
my_print_defaults myisampack mysql_config_editor mysql_secure_installation mysqladmin mysqld-debug mysqldumpslow mysqlslap replace
myisam_ftdump mysql mysql_embedded mysql_ssl_rsa_setup mysqlbinlog mysqld_multi mysqlimport mysqltest_embedded resolve_stack_dump
# ./mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/mysql/data
# cat /mysql/log/mysql-error.log
2018-08-05T03:42:33.946662Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-08-05T03:42:33.946725Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2018-08-05T03:42:33.946729Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.
2018-08-05T03:42:35.019167Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-08-05T03:42:35.140139Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-08-05T03:42:35.208001Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 9747442b-9861-11e8-b272-00163e04364b.
2018-08-05T03:42:35.211031Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-08-05T03:42:35.211514Z 1 [Note] A temporary password is generated for root@localhost: avi>2Wlg%Khz
6.5.mysql数据库加密
# ./mysql_ssl_rsa_setup --datadir=/mysql/data
Generating a 2048 bit RSA private key
.......................+++
......+++
writing new private key to 'ca-key.pem'
-----
Generating a 2048 bit RSA private key
............................+++
........+++
writing new private key to 'server-key.pem'
-----
Generating a 2048 bit RSA private key
............................................................................................+++
......................+++
writing new private key to 'client-key.pem'
# ./mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.23
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> use mysql;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> set password=password('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> grant all privileges on *.* to idba@'%' identified by '123456';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
7.设置mysql服务开机自启动
# chkconfig --add mysqld
# chkconfig mysqld on
# chkconfig --list | grep mysqld
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
# mysql --version
mysql Ver 14.14 Distrib 5.7.23, for linux-glibc2.12 (x86_64) using EditLine wrapper
# mysql -h 192.168.80.168 -uidba -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.23 MySQL Community Server (GPL)
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> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> SELECT COUNT(*) FROM `user`;
+----------+
| COUNT(*) |
+----------+
| 4 |
+----------+
1 row in set (0.00 sec)
# reboot
Connection to 192.168.80.168 closed by remote host.
Connection to 192.168.80.168 closed.
➜ ~ ssh root@192.168.80.168
root@192.168.80.168's password:
Last login: Sun Aug 5 10:53:44 2018 from 222.22.22.222
Welcome to Alibaba Cloud Elastic Compute Service !
-bash: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory
# ps -ef |grep mysql
root 787 1 0 12:33 ? 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/mysql/data --pid-file=/mysql/pid/mysql.pid
mysql 1201 787 0 12:33 ? 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/mysql/log/mysql-error.log --pid-file=/mysql/pid/mysql.pid --socket=/mysql/sock/mysql.sock --port=3306
root 1320 1302 0 12:33 pts/0 00:00:00 grep --color=auto mysql
successfully.
附录1:
Error: ./mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
yum install libaio*
Error: # ./mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/mysql/data
2018-08-05T03:39:51.400548Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-08-05T03:39:51.400615Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2018-08-05T03:39:51.400620Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.
2018-08-05T03:39:51.402275Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
2018-08-05T03:39:51.402308Z 0 [ERROR] Aborting
1.检查:配置文件没有问题
2.检查:所有涉及文件已归属mysql用户没问题
3.检查:数据库“bind-address”没闻到
4.清空“/mysql/data”下编译的所有,即数据库文件,重新执行:
./mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/mysql/data
-bash: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory
vim /etc/environment
LC_ALL=en_US.UTF-8
LANG=en_US.UTF-8
附录2:忘记Mysql的root用户密码的解决方法
-- 先打开一个Terminal,在 /usr/local/mysql/bin ,下执行:
# sudo mysqld_safe --skip-grant-tables
-- 再新打开一个Terminal, 打开安全模式的mysql, 连接的时候不需要密码:
# mysql -u root -p
# UPDATE mysql.user SET authentication_string=PASSWORD('123456') WHERE User='root';
# FLUSH PRIVILEGES;
附录3:创建数据库
# CREATE DATABASE IF NOT EXISTS my_test DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;
# GRANT ALL PRIVILEGES ON *.* TO dba@'%' IDENTIFIED BY '123456';
# FLUSH PRIVILEGES;