【MySQL】centos7.6安装mysql5.7

先抛日志,后续整理

[root@localhost ~]# groupadd mysql
[root@localhost ~]# useradd -r -g mysql mysql
[root@localhost ~]# id mysql
uid=997(mysql) gid=1000(mysql) 组=1000(mysql)
[root@localhost app]# mv mysql-5.7.21-linux-glibc2.12-x86_64 /usr/local/
[root@localhost home]# cd /usr/local/
[root@localhost local]# ll
总用量 0
drwxr-xr-x.  2 root  root    6 4月  11 2018 bin
drwxr-xr-x.  2 root  root    6 4月  11 2018 etc
drwxr-xr-x.  2 root  root    6 4月  11 2018 games
drwxr-xr-x.  2 root  root    6 4月  11 2018 include
drwxr-xr-x.  3 root  root   26 11月 19 12:04 java
drwxr-xr-x.  2 root  root    6 4月  11 2018 lib
drwxr-xr-x.  2 root  root    6 4月  11 2018 lib64
drwxr-xr-x.  2 root  root    6 4月  11 2018 libexec
drwxr-xr-x.  9 root  root  129 11月 19 20:37 mysql-5.7.21-linux-glibc2.12-x86_64
drwxr-xr-x. 11 root  root  151 10月  2 16:26 nginx
drwxr-xr-x.  2 root  root    6 4月  11 2018 sbin
drwxr-xr-x.  5 root  root   49 10月  2 10:30 share
drwxr-xr-x.  2 root  root    6 4月  11 2018 src
[root@localhost local]# mv mysql-5.7.21-linux-glibc2.12-x86_64/ mysql
[root@localhost local]# cd mysql
[root@localhost mysql]# chown -R mysql:mysql ./
[root@localhost mysql]# ll
总用量 36
drwxr-xr-x.  2 mysql mysql  4096 11月 19 20:37 bin
-rw-r--r--.  1 mysql mysql 17987 12月 28 2017 COPYING
drwxr-xr-x.  2 mysql mysql    55 11月 19 20:37 docs
drwxr-xr-x.  3 mysql mysql  4096 11月 19 20:37 include
drwxr-xr-x.  5 mysql mysql   229 11月 19 20:37 lib
drwxr-xr-x.  4 mysql mysql    30 11月 19 20:37 man
-rw-r--r--.  1 mysql mysql  2478 12月 28 2017 README
drwxr-xr-x. 28 mysql mysql  4096 11月 19 20:37 share
drwxr-xr-x.  2 mysql mysql    90 11月 19 20:37 support-files
[root@localhost mysql]# ll
总用量 36
drwxr-xr-x.  2 mysql mysql  4096 11月 19 20:37 bin
-rw-r--r--.  1 mysql mysql 17987 12月 28 2017 COPYING
drwxr-xr-x.  2 mysql mysql    55 11月 19 20:37 docs
drwxr-xr-x.  3 mysql mysql  4096 11月 19 20:37 include
drwxr-xr-x.  5 mysql mysql   229 11月 19 20:37 lib
drwxr-xr-x.  4 mysql mysql    30 11月 19 20:37 man
-rw-r--r--.  1 mysql mysql  2478 12月 28 2017 README
drwxr-xr-x. 28 mysql mysql  4096 11月 19 20:37 share
drwxr-xr-x.  2 mysql mysql    90 11月 19 20:37 support-files
[root@localhost mysql]# mkdir data
[root@localhost mysql]# ll
总用量 36
drwxr-xr-x.  2 mysql mysql  4096 11月 19 20:37 bin
-rw-r--r--.  1 mysql mysql 17987 12月 28 2017 COPYING
drwxr-xr-x.  2 root  root      6 11月 19 20:51 data
drwxr-xr-x.  2 mysql mysql    55 11月 19 20:37 docs
drwxr-xr-x.  3 mysql mysql  4096 11月 19 20:37 include
drwxr-xr-x.  5 mysql mysql   229 11月 19 20:37 lib
drwxr-xr-x.  4 mysql mysql    30 11月 19 20:37 man
-rw-r--r--.  1 mysql mysql  2478 12月 28 2017 README
drwxr-xr-x. 28 mysql mysql  4096 11月 19 20:37 share
drwxr-xr-x.  2 mysql mysql    90 11月 19 20:37 support-files
[root@localhost data]# chown -R mysql:mysql data
[root@localhost mysql]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
2019-11-19T12:52:53.616942Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-11-19T12:52:53.866073Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-11-19T12:52:54.436977Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-11-19T12:52:54.493777Z 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: 80deae61-0acb-11ea-a0b6-000c29bc4160.
2019-11-19T12:52:54.494679Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-11-19T12:52:54.495737Z 1 [Note] A temporary password is generated for root@localhost: jqhllun+j1!F
[root@localhost mysql]# cp  /etc/my.cnf /etc/my_bak.cnf
[root@localhost mysql]# vi /etc/my.cnf
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
#不区分大小写
lower_case_table_names = 1
#不开启sql严格模式
sql_mode = "STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
log-error=/var/log/mysqld.log
pid-file=/usr/local/mysql/data/mysqld.pid
~
~
"/etc/my.cnf" 12L, 430C written
[root@localhost mysql]#  cp /usr/local/mysql/support-files/mysql.server  /etc/init.d/mysqld
[root@localhost mysql]# vim /etc/init.d/mysqld  
  1 #!/bin/sh
  2 # Copyright Abandoned 1996 TCX DataKonsult AB & Monty Program KB & Detron HB
  3 # This file is public domain and comes with NO WARRANTY of any kind
  4 
  5 # MySQL daemon start/stop script.
  6 
  7 # Usually this is put in /etc/init.d (at least on machines SYSV R4 based
  8 # systems) and linked to /etc/rc3.d/S99mysql and /etc/rc0.d/K01mysql.
  9 # When this is done the mysql server will be started when the machine is
 10 # started and shut down when the systems goes down.
 11 
 12 # Comments to support chkconfig on RedHat Linux
 13 # chkconfig: 2345 64 36
 14 # description: A very fast and reliable SQL database engine.
 15 
 16 # Comments to support LSB init script conventions
 17 ### BEGIN INIT INFO
 18 # Provides: mysql
 19 # Required-Start: $local_fs $network $remote_fs
 20 # Should-Start: ypbind nscd ldap ntpd xntpd
 21 # Required-Stop: $local_fs $network $remote_fs
 22 # Default-Start:  2 3 4 5
 23 # Default-Stop: 0 1 6
 24 # Short-Description: start and stop MySQL
 25 # Description: MySQL is a very fast and reliable SQL database engine.
 26 ### END INIT INFO
 27 
 28 # If you install MySQL on some other places than /usr/local/mysql, then you
 29 # have to do one of the following things for this script to work:
 30 #
 31 # - Run this script from within the MySQL installation directory
 32 # - Create a /etc/my.cnf file with the following information:
 33 #   [mysqld]
 34 #   basedir=<path-to-mysql-installation-directory>
 35 # - Add the above to any other configuration file (for example ~/.my.ini)
 36 #   and copy my_print_defaults to /usr/bin
 37 # - Add the path to the mysql-installation-directory to the basedir variable
 38 #   below.
 39 #
 40 # If you want to affect other MySQL variables, you should make your changes
 41 # in the /etc/my.cnf, ~/.my.cnf or other MySQL configuration files.
 42 
 43 # If you change base dir, you must also change datadir. These may get
 44 # overwritten by settings in the MySQL configuration files.
 45 
 46 basedir=/usr/local/mysql
 47 datadir=/usr/local/mysql/data
 48 
 49 # Default value, in seconds, afterwhich the script should timeout waiting
 50 # for server start. 
 51 # Value here is overriden by value in my.cnf.
 52 # 0 means don't wait at all
 53 # Negative numbers mean to wait indefinitely
 54 service_startup_timeout=900
 55 
 56 # Lock directory for RedHat / SuSE.
 57 lockdir='/var/lock/subsys'
 58 lock_file_path="$lockdir/mysql"
 59 
 60 # The following variables are only set for letting mysql.server find things.
 61 
 62 # Set some defaults
 63 mysqld_pid_file_path=
 64 if test -z "$basedir"
 65 then
 66   basedir=/usr/local/mysql
 67   bindir=/usr/local/mysql/bin
 68   if test -z "$datadir"
 69   then
 70     datadir=/usr/local/mysql/data
 71   fi
"/etc/rc.d/init.d/mysqld" 376L, 10619C 已写入                                                                                                        
[root@localhost mysql]# service mysqld start 
Starting MySQL. SUCCESS! 
[root@localhost mysql]# systemctl enable mysqld
mysqld.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig mysqld on
[root@localhost mysql]#  mysql -uroot -p
-bash: mysql: 未找到命令
[root@localhost mysql]# ln -s /usr/local/mysql/bin/mysql /usr/bin
[root@localhost mysql]# 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.21

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> alter user 'root'@'localhost' identified by 'root';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges; 
Query OK, 0 rows affected (0.01 sec)

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root1'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> quit
Bye
[root@localhost mysql]# 

参考:
https://blog.csdn.net/qq_40200087/article/details/89479137
https://www.cnblogs.com/rayment/p/7240562.html

2021年12月17日补充
今天登录遇到的一个报错

Can't connect to local MySQL server through socket '/tmp/mysql.sock'

用以下命令登录

mysql -uroot -h 127.0.0.1 -p 

参考:亲测有效,解决Can 't connect to local MySQL server through socket '/tmp/mysql.sock '(2) ";

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

实施工程师木易

感谢支持

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值