Linux mysql 5.7.26安装配置

Linux mysql 5.7.26安装配置

环境准备:
CentOS 7
mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
查看磁盘空间
[root@promote mysql-5.7.26]# df -h
文件系统                 容量  已用  可用 已用% 挂载点
devtmpfs                 1.9G     0  1.9G    0% /dev
tmpfs                    1.9G     0  1.9G    0% /dev/shm
tmpfs                    1.9G   12M  1.9G    1% /run
tmpfs                    1.9G     0  1.9G    0% /sys/fs/cgroup
/dev/mapper/centos-root   50G  1.8G   49G    4% /
/dev/sda1               1014M  150M  865M   15% /boot
/dev/mapper/centos-home  146G  3.1G  142G    3% /home
tmpfs                    378M     0  378M    0% /run/user/0
上传解压
[root@promote home]# tar -zxvf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz 
[root@promote home]# ls
mysql-5.7.26-linux-glibc2.12-x86_64  mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
[root@promote home]# mv mysql-5.7.26-linux-glibc2.12-x86_64 mysql-5.7.26
[root@promote home]# ls
mysql-5.7.26  mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
[root@promote home]# cd mysql-5.7.26
[root@promote mysql-5.7.26]# ls
bin  COPYING  docs  include  lib  man  README  share  support-files
添加用户组
[root@promote mysql-5.7.26]# groups mysql
groups: mysql: no such user
[root@promote mysql-5.7.26]# groupadd mysql
[root@promote mysql-5.7.26]# useradd -r -g mysql mysql
[root@promote mysql-5.7.26]# groups mysql
mysql : mysql
配置mysql配置文件/etc/my.cnf
[root@promote mysql-5.7.26]# cat /etc/my.cnf | grep -v '#'
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
symbolic-links=0

[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid

!includedir /etc/my.cnf.d


[root@promote mysql-5.7.26]# mkdir data
[root@promote mysql-5.7.26]# ll
总用量 36
drwxr-xr-x.  2 root root   4096 11月 15 14:14 bin
-rw-r--r--.  1 7161 31415 17987 4月  13 2019 COPYING
drwxr-xr-x.  2 root root      6 11月 15 14:22 data
drwxr-xr-x.  2 root root     55 11月 15 14:14 docs
drwxr-xr-x.  3 root root   4096 11月 15 14:13 include
drwxr-xr-x.  5 root root    230 11月 15 14:14 lib
drwxr-xr-x.  4 root root     30 11月 15 14:14 man
-rw-r--r--.  1 7161 31415  2478 4月  13 2019 README
drwxr-xr-x. 28 root root   4096 11月 15 14:14 share
drwxr-xr-x.  2 root root     90 11月 15 14:14 support-files
[root@promote mysql-5.7.26]# chown -R mysql:mysql ./
[root@promote mysql-5.7.26]# ll
总用量 36
drwxr-xr-x.  2 mysql mysql  4096 11月 15 14:14 bin
-rw-r--r--.  1 mysql mysql 17987 4月  13 2019 COPYING
drwxr-xr-x.  2 mysql mysql     6 11月 15 14:22 data
drwxr-xr-x.  2 mysql mysql    55 11月 15 14:14 docs
drwxr-xr-x.  3 mysql mysql  4096 11月 15 14:13 include
drwxr-xr-x.  5 mysql mysql   230 11月 15 14:14 lib
drwxr-xr-x.  4 mysql mysql    30 11月 15 14:14 man
-rw-r--r--.  1 mysql mysql  2478 4月  13 2019 README
drwxr-xr-x. 28 mysql mysql  4096 11月 15 14:14 share
drwxr-xr-x.  2 mysql mysql    90 11月 15 14:14 support-files
[root@promote mysql-5.7.26]# pwd
/home/mysql-5.7.26
[root@promote mysql-5.7.26]# cd data/
[root@promote data]# pwd
/home/mysql-5.7.26/data
[root@promote data]# vi /etc/my.cnf
[root@promote data]# cat /etc/my.cnf | grep -v '#'
[mysqld]
basedir=/home/mysql-5.7.26
datadir=/home/mysql-5.7.26/data
port=3306
default-character-set=utf8
character-set-server=utf8
skip-name-resolve
default-storage-engine=INNODB
lower_case_table_names=1    
max_allowed_packet=100M

socket=/var/lib/mysql/mysql.sock
symbolic-links=0

[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid

!includedir /etc/my.cnf.d
完善my.cnf配置项
[root@promote data]# cat /var/lib/mysql/mysql.sock
cat: /var/lib/mysql/mysql.sock: 没有那个文件或目录
[root@promote data]# cd /var/lib
[root@promote lib]# ls
alternatives  chrony  dhclient  initramfs  machines  NetworkManager  plymouth  postfix  rpm-state  stateless  tuned   yum
authconfig    dbus    games     logrotate  misc      os-prober       polkit-1  rpm      rsyslog    systemd    vmware
[root@promote lib]# mkdir mysql
[root@promote lib]# ll
总用量 4
drwxr-xr-x. 2 root    root      55 11月 15 08:18 alternatives
drwx------. 3 root    root      18 11月 15 08:21 authconfig
drwxr-xr-x. 2 chrony  chrony    19 11月 15 14:09 chrony
drwxr-xr-x. 2 root    root       6 3月  14 2019 dbus
drwxr-xr-x. 2 root    root       6 8月   9 2019 dhclient
drwxr-xr-x. 2 root    root       6 4月  11 2018 games
drwxr-xr-x. 2 root    root       6 8月   9 2019 initramfs
drwxr-xr-x. 2 root    root      30 11月 15 09:37 logrotate
drwx------. 2 root    root       6 11月 15 08:18 machines
drwxr-xr-x. 2 root    root      37 11月 15 08:26 misc
drwxr-xr-x. 2 root    root       6 11月 15 14:29 mysql
drwx------. 2 root    root     168 11月 15 13:29 NetworkManager
drwxr-xr-x. 2 root    root       6 11月  6 2016 os-prober
drwxr-xr-x. 2 root    root      27 11月 15 08:18 plymouth
drwxr-x---. 3 root    polkitd   28 11月 15 08:18 polkit-1
drwx------. 2 postfix root      25 11月 15 08:26 postfix
drwxr-xr-x. 2 root    root    4096 11月 15 08:42 rpm
drwxr-xr-x. 2 root    root       6 4月  11 2018 rpm-state
drwx------. 2 root    root      29 11月 15 14:23 rsyslog
drwxr-xr-x. 4 root    root      35 11月 15 08:18 stateless
drwxr-xr-x. 4 root    root      56 11月 15 08:18 systemd
drwxr-xr-x. 2 root    root       6 8月   8 2019 tuned
drwxr-xr-x. 3 root    root      20 11月 15 08:26 vmware
drwxr-xr-x. 6 root    root      80 11月 15 08:42 yum
[root@promote lib]# chown mysql mysql
[root@promote lib]# chgrp mysql mysql
[root@promote lib]# ll
总用量 4
drwxr-xr-x. 2 root    root      55 11月 15 08:18 alternatives
drwx------. 3 root    root      18 11月 15 08:21 authconfig
drwxr-xr-x. 2 chrony  chrony    19 11月 15 14:09 chrony
drwxr-xr-x. 2 root    root       6 3月  14 2019 dbus
drwxr-xr-x. 2 root    root       6 8月   9 2019 dhclient
drwxr-xr-x. 2 root    root       6 4月  11 2018 games
drwxr-xr-x. 2 root    root       6 8月   9 2019 initramfs
drwxr-xr-x. 2 root    root      30 11月 15 09:37 logrotate
drwx------. 2 root    root       6 11月 15 08:18 machines
drwxr-xr-x. 2 root    root      37 11月 15 08:26 misc
drwxr-xr-x. 2 mysql   mysql      6 11月 15 14:29 mysql
drwx------. 2 root    root     168 11月 15 13:29 NetworkManager
drwxr-xr-x. 2 root    root       6 11月  6 2016 os-prober
drwxr-xr-x. 2 root    root      27 11月 15 08:18 plymouth
drwxr-x---. 3 root    polkitd   28 11月 15 08:18 polkit-1
drwx------. 2 postfix root      25 11月 15 08:26 postfix
drwxr-xr-x. 2 root    root    4096 11月 15 08:42 rpm
drwxr-xr-x. 2 root    root       6 4月  11 2018 rpm-state
drwx------. 2 root    root      29 11月 15 14:23 rsyslog
drwxr-xr-x. 4 root    root      35 11月 15 08:18 stateless
drwxr-xr-x. 4 root    root      56 11月 15 08:18 systemd
drwxr-xr-x. 2 root    root       6 8月   8 2019 tuned
drwxr-xr-x. 3 root    root      20 11月 15 08:26 vmware
drwxr-xr-x. 6 root    root      80 11月 15 08:42 yum
初始化mysql
[root@promote lib]# cd /home/mysql-5.7.26/bin/
[root@promote bin]# ls
innochecksum    my_print_defaults           mysql_config         mysqldump         mysqlpump                  mysql_tzinfo_to_sql  resolve_stack_dump
lz4_decompress  mysql                       mysql_config_editor  mysqldumpslow     mysql_secure_installation  mysql_upgrade        zlib_decompress
myisamchk       mysqladmin                  mysqld               mysql_embedded    mysqlshow                  mysqlxtest
myisam_ftdump   mysqlbinlog                 mysqld-debug         mysqlimport       mysqlslap                  perror
myisamlog       mysqlcheck                  mysqld_multi         mysql_install_db  mysql_ssl_rsa_setup        replace
myisampack      mysql_client_test_embedded  mysqld_safe          mysql_plugin      mysqltest_embedded         resolveip
[root@promote bin]# ./mysqld --initialize --user=mysql --basedir=/home/mysql-5.7.26 --datadir=/home/mysql-5.7.26/data
2020-11-15T06:34:25.526824Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-11-15T06:34:25.951996Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-11-15T06:34:26.329336Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-11-15T06:34:26.404586Z 0 [ERROR] unknown variable 'default-character-set=utf8'
2020-11-15T06:34:26.404604Z 0 [ERROR] Aborting

[root@promote bin]# vi /etc/my.cnf
[root@promote bin]# cat /etc/my.cnf | grep -v '#'
[mysqld]
basedir=/home/mysql-5.7.26
datadir=/home/mysql-5.7.26/data
port=3306
skip-name-resolve
default-storage-engine=INNODB
lower_case_table_names=1    
max_allowed_packet=100M

socket=/var/lib/mysql/mysql.sock
symbolic-links=0

[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid

!includedir /etc/my.cnf.d
[root@promote bin]# ./mysqld --initialize --user=mysql --basedir=/home/mysql-5.7.26 --datadir=/home/mysql-5.7.26/data
2020-11-15T06:37:06.366230Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-11-15T06:37:06.368811Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
2020-11-15T06:37:06.368835Z 0 [ERROR] Aborting
[root@promote home]# cd /var/lib/mysql/
[root@promote mysql]# ls
[root@promote mysql]# cd /home/mysql-5.7.26/data/
[root@promote data]# ls
ib_buffer_pool  ibdata1  ib_logfile0  ib_logfile1
[root@promote data]# rm -rf *
[root@promote data]# ls
[root@promote data]# cd ../bin/
[root@promote bin]# ./mysqld --initialize --user=mysql --basedir=/home/mysql-5.7.26 --datadir=/home/mysql-5.7.26/data
2020-11-15T06:42:00.328438Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-11-15T06:42:00.727354Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-11-15T06:42:00.807571Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-11-15T06:42:00.869241Z 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: aa368e3a-270d-11eb-8dd6-000c29eed173.
2020-11-15T06:42:00.871305Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-11-15T06:42:00.872700Z 1 [Note] A temporary password is generated for root@localhost: ol_ott0k&j-C
设置开机自启
root@promote bin]# cd ../
[root@promote mysql-5.7.26]# cp /home/mysql-5.7.26/support-files/mysql.server /etc/init.d/mysql
[root@promote mysql-5.7.26]# chkconfig --add mysql
[root@promote mysql-5.7.26]# chkconfig --list

注:该输出结果只显示 SysV 服务,并不包含
原生 systemd 服务。SysV 配置数据
可能被原生 systemd 配置覆盖。 

      要列出 systemd 服务,请执行 'systemctl list-unit-files'。
      查看在具体 target 启用的服务请执行
      'systemctl list-dependencies [target]'。

mysql          	0:关	1:关	2:开	3:开	4:开	5:开	6:关
netconsole     	0:关	1:关	2:关	3:关	4:关	5:关	6:关
network        	0:关	1:关	2:开	3:开	4:开	5:开	6:关
[root@promote mysql-5.7.26]# cat /var/log/mariadb/mariadb.log
cat: /var/log/mariadb/mariadb.log: 没有那个文件或目录
[root@promote mysql-5.7.26]# cd /var/log/mariadb
-bash: cd: /var/log/mariadb: 没有那个文件或目录
[root@promote mysql-5.7.26]# cd /var/log/
[root@promote log]# mkdir mariadb
[root@promote log]# ll
总用量 360
drwxr-xr-x. 2 root   root      232 11月 15 08:21 anaconda
drwx------. 2 root   root       23 11月 15 08:26 audit
-rw-------. 1 root   root     8841 11月 15 08:26 boot.log
-rw-------. 1 root   utmp        0 11月 15 08:18 btmp
drwxr-xr-x. 2 chrony chrony      6 8月   8 2019 chrony
-rw-------. 1 root   root     2967 11月 15 15:01 cron
-rw-r--r--. 1 root   root   124678 11月 15 08:26 dmesg
-rw-r-----. 1 root   root        0 11月 15 08:26 firewalld
-rw-r--r--. 1 root   root      193 11月 15 08:17 grubby_prune_debug
-rw-r--r--. 1 root   root   292000 11月 15 14:18 lastlog
-rw-------. 1 root   root      194 11月 15 08:26 maillog
drwxr-xr-x. 2 root   root       25 11月 15 15:05 mariadb
-rw-------. 1 root   root   165071 11月 15 15:17 messages
drwxr-xr-x. 2 root   root        6 11月 15 08:21 rhsm
-rw-------. 1 root   root     3671 11月 15 15:02 secure
-rw-------. 1 root   root        0 11月 15 08:18 spooler
-rw-------. 1 root   root    64000 11月 15 14:18 tallylog
drwxr-xr-x. 2 root   root       23 11月 15 08:26 tuned
-rw-------. 1 root   root      775 11月 15 08:26 vmware-network.log
-rw-------. 1 root   root     1404 11月 15 08:26 vmware-vgauthsvc.log.0
-rw-r--r--. 1 root   root     3134 11月 15 13:28 vmware-vmsvc.log
-rw-rw-r--. 1 root   utmp     3840 11月 15 13:29 wtmp
-rw-------. 1 root   root       69 11月 15 08:42 yum.log
[root@promote log]# chown -R mysql:mysql mariadb/
[root@promote log]# 
[root@promote log]# ll
总用量 360
drwxr-xr-x. 2 root   root      232 11月 15 08:21 anaconda
drwx------. 2 root   root       23 11月 15 08:26 audit
-rw-------. 1 root   root     8841 11月 15 08:26 boot.log
-rw-------. 1 root   utmp        0 11月 15 08:18 btmp
drwxr-xr-x. 2 chrony chrony      6 8月   8 2019 chrony
-rw-------. 1 root   root     2967 11月 15 15:01 cron
-rw-r--r--. 1 root   root   124678 11月 15 08:26 dmesg
-rw-r-----. 1 root   root        0 11月 15 08:26 firewalld
-rw-r--r--. 1 root   root      193 11月 15 08:17 grubby_prune_debug
-rw-r--r--. 1 root   root   292000 11月 15 14:18 lastlog
-rw-------. 1 root   root      194 11月 15 08:26 maillog
drwxr-xr-x. 2 mysql  mysql      25 11月 15 15:05 mariadb
-rw-------. 1 root   root   165071 11月 15 15:17 messages
drwxr-xr-x. 2 root   root        6 11月 15 08:21 rhsm
-rw-------. 1 root   root     3671 11月 15 15:02 secure
-rw-------. 1 root   root        0 11月 15 08:18 spooler
-rw-------. 1 root   root    64000 11月 15 14:18 tallylog
drwxr-xr-x. 2 root   root       23 11月 15 08:26 tuned
-rw-------. 1 root   root      775 11月 15 08:26 vmware-network.log
-rw-------. 1 root   root     1404 11月 15 08:26 vmware-vgauthsvc.log.0
-rw-r--r--. 1 root   root     3134 11月 15 13:28 vmware-vmsvc.log
-rw-rw-r--. 1 root   utmp     3840 11月 15 13:29 wtmp
-rw-------. 1 root   root       69 11月 15 08:42 yum.log
[root@promote log]# cd mariadb/
[root@promote mariadb]# touch mariadb.log
[root@promote mariadb]# cat /var/run/mariadb/mariadb.pid
cat: /var/run/mariadb/mariadb.pid: 没有那个文件或目录
[root@promote mariadb]# cd /var/run/mariadb/
-bash: cd: /var/run/mariadb/: 没有那个文件或目录
[root@promote mariadb]# cd /var/run/
[root@promote run]# mkdir mariadb
root@promote run]# ll
总用量 28
-rw-r--r--.  1 root   root      4 11月 15 08:26 auditd.pid
drwxr-xr-x.  2 root   root     80 11月 15 08:26 blkid
drwxr-x---.  2 chrony chrony   80 11月 15 13:29 chrony
drwxr-xr-x.  2 root   root     40 11月 15 08:26 console
-rw-r--r--.  1 root   root      4 11月 15 08:26 crond.pid
----------.  1 root   root      0 11月 15 08:26 cron.reboot
drwx------.  2 root   root     40 11月 15 08:26 cryptsetup
drwxr-xr-x.  2 root   root     60 11月 15 08:26 dbus
-rw-r--r--.  1 root   root      6 11月 15 15:13 dhclient-ens33.pid
prw-------.  1 root   root      0 11月 15 08:26 dmeventd-client
prw-------.  1 root   root      0 11月 15 08:26 dmeventd-server
-rw-------.  1 root   root      0 11月 15 08:26 ebtables.lock
drwxr-xr-x.  2 root   root     40 11月 15 08:26 faillock
drwxr-x---.  2 root   root     40 11月 15 13:29 firewalld
drwxr-xr-x.  4 root   root    120 11月 15 08:26 initramfs
drwxr-xr-x.  5 root   root    120 11月 15 09:37 lock
drwxr-xr-x.  3 root   root     60 11月 15 08:26 log
drwx------.  2 root   root     80 11月 15 08:26 lvm
-rw-r--r--.  1 root   root      4 11月 15 08:26 lvmetad.pid
drwxr-xr-x.  2 root   root     60 11月 15 15:07 mariadb
drwxr-xr-x.  2 root   root     40 11月 15 08:26 mount
drwxrwxr-x.  2 root   root     40 11月 15 08:26 netreport
drwxr-xr-x.  3 root   root    120 11月 15 13:29 NetworkManager
drwxr-xr-x.  2 root   root     40 11月 15 08:26 plymouth
drwxr-xr-x.  2 root   root     40 11月 15 08:26 sepermit
drwxr-xr-x.  2 root   root     40 11月 15 08:26 setrans
-rw-r--r--.  1 root   root      5 11月 15 08:26 sshd.pid
drwx--x--x.  3 root   root     60 11月 15 08:26 sudo
-rw-------.  1 root   root      4 11月 15 08:26 syslogd.pid
drwxr-xr-x. 18 root   root    440 11月 15 15:02 systemd
drwxr-xr-x.  2 root   root     60 11月 15 08:26 tmpfiles.d
drwxr-xr-x.  2 root   root     60 11月 15 08:26 tuned
drwxr-xr-x.  7 root   root    160 11月 15 13:29 udev
drwxr-xr-x.  3 root   root     60 11月 15 08:28 user
-rw-rw-r--.  1 root   utmp   1920 11月 15 13:29 utmp
drwxr-xr-x.  2 root   root     60 11月 15 08:26 vmware
-rw-------.  1 root   root      0 11月 15 08:26 xtables.lock
[root@promote run]# chown -R mysql:mysql mariadb/
[root@promote run]# ll
总用量 28
-rw-r--r--.  1 root   root      4 11月 15 08:26 auditd.pid
drwxr-xr-x.  2 root   root     80 11月 15 08:26 blkid
drwxr-x---.  2 chrony chrony   80 11月 15 13:29 chrony
drwxr-xr-x.  2 root   root     40 11月 15 08:26 console
-rw-r--r--.  1 root   root      4 11月 15 08:26 crond.pid
----------.  1 root   root      0 11月 15 08:26 cron.reboot
drwx------.  2 root   root     40 11月 15 08:26 cryptsetup
drwxr-xr-x.  2 root   root     60 11月 15 08:26 dbus
-rw-r--r--.  1 root   root      6 11月 15 15:13 dhclient-ens33.pid
prw-------.  1 root   root      0 11月 15 08:26 dmeventd-client
prw-------.  1 root   root      0 11月 15 08:26 dmeventd-server
-rw-------.  1 root   root      0 11月 15 08:26 ebtables.lock
drwxr-xr-x.  2 root   root     40 11月 15 08:26 faillock
drwxr-x---.  2 root   root     40 11月 15 13:29 firewalld
drwxr-xr-x.  4 root   root    120 11月 15 08:26 initramfs
drwxr-xr-x.  5 root   root    120 11月 15 09:37 lock
drwxr-xr-x.  3 root   root     60 11月 15 08:26 log
drwx------.  2 root   root     80 11月 15 08:26 lvm
-rw-r--r--.  1 root   root      4 11月 15 08:26 lvmetad.pid
drwxr-xr-x.  2 mysql  mysql    60 11月 15 15:07 mariadb
drwxr-xr-x.  2 root   root     40 11月 15 08:26 mount
drwxrwxr-x.  2 root   root     40 11月 15 08:26 netreport
drwxr-xr-x.  3 root   root    120 11月 15 13:29 NetworkManager
drwxr-xr-x.  2 root   root     40 11月 15 08:26 plymouth
drwxr-xr-x.  2 root   root     40 11月 15 08:26 sepermit
drwxr-xr-x.  2 root   root     40 11月 15 08:26 setrans
-rw-r--r--.  1 root   root      5 11月 15 08:26 sshd.pid
drwx--x--x.  3 root   root     60 11月 15 08:26 sudo
-rw-------.  1 root   root      4 11月 15 08:26 syslogd.pid
drwxr-xr-x. 18 root   root    440 11月 15 15:02 systemd
drwxr-xr-x.  2 root   root     60 11月 15 08:26 tmpfiles.d
drwxr-xr-x.  2 root   root     60 11月 15 08:26 tuned
drwxr-xr-x.  7 root   root    160 11月 15 13:29 udev
drwxr-xr-x.  3 root   root     60 11月 15 08:28 user
-rw-rw-r--.  1 root   utmp   1920 11月 15 13:29 utmp
drwxr-xr-x.  2 root   root     60 11月 15 08:26 vmware
-rw-------.  1 root   root      0 11月 15 08:26 xtables.lock
[root@promote run]# cd mariadb
[root@promote mariadb]# touch mariadb.pid
启动并查看运行状态
[root@promote run]# service mysql start
Starting MySQL.. SUCCESS! 
[root@promote run]# service mysql status
 SUCCESS! MySQL running (18553)
设置软连接 全局service mysql xxx 命令启动
[root@promote run]# ln -s /var/lib/mysql/mysql.sock /tmp/
[root@promote run]# ln -s /home/mysql-5.7.26/bin/mysql /usr/bin/
[root@promote run]# service mysql
Usage: mysql  {start|stop|restart|reload|force-reload|status}  [ MySQL server options ]
[root@promote run]# service mysql status
 SUCCESS! MySQL running (18553)
登录并修改密码
root@promote run]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.26

Copyright (c) 2000, 2019, 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'
    -> \g
Query OK, 0 rows affected (0.00 sec)

mysql> select host,user from mysql.user
    -> \g
+-----------+---------------+
| host      | user          |
+-----------+---------------+
| localhost | mysql.session |
| localhost | mysql.sys     |
| localhost | root          |
+-----------+---------------+
3 rows in set (0.00 sec)

mysql> flush privileges
    -> \g
Query OK, 0 rows affected (0.01 sec)

mysql> exit
Bye

[root@promote run]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.26 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, 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> update user set host='%' where user = 'root'
    -> \g
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> flush privileges
    -> \g
Query OK, 0 rows affected (0.00 sec)

mysql>  select host,user from mysql.user
    -> \g
+-----------+---------------+
| host      | user          |
+-----------+---------------+
| %         | root          |
| localhost | mysql.session |
| localhost | mysql.sys     |
+-----------+---------------+
3 rows in set (0.00 sec)

mysql> exit
Bye
开放防火墙端口
[root@promote run]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
success
[root@promote run]# firewall-cmd --reload
success
[root@promote run]# firewall-cmd --list-ports
3306/tcp
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值