Centos 7安裝MySql(5.7.26解壓版)
1、卸載centos7
自帶的 MariaDB
[root@VM_0_14_centos ~]# rpm -qa|grep mariadb
mariadb-libs-5.5.56-2.el7.x86_64
[root@VM_0_14_centos ~]# rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64
error: package mariadb-libs-55.56mariadb-libs-5.5.56-2.el7.x86_64 is not installed
[root@VM_0_14_centos ~]#
2、刪除/etc
下my.cnf
配置文件(如果存在的話)、檢查mysql
是否存在
[root@VM_0_14_centos ~]# rm -rf /etc/my.cnf
[root@VM_0_14_centos ~]# rpm -qa | grep mysql
3、官網(wǎng)下載源碼包
下載地址
4仁期、解壓安裝包
tar -xvf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
5、修改解壓出來(lái)的文件夾移動(dòng)到 /usr/local/mysql
[root@VM_0_14_centos download]# mv /usr/local/download/mysql-5.7.26-linux-glibc2.12-x86_64 /usr/local/mysql
6、進(jìn)入mysql目錄跛蛋,新建data目錄
[root@VM_0_14_centos download]# cd /usr/local/mysql/
[root@VM_0_14_centos mysql]# mkdir data
7熬的、創(chuàng)建系統(tǒng)用戶(hù)組和用戶(hù)
[root@VM_0_14_centos mysql]# cat /etc/group --查看所有用戶(hù)組信息是否存在mysql組,不存在則創(chuàng)建赊级,存在則直接新建用戶(hù)
[root@VM_0_14_centos mysql]# groupadd mysql ---新建一個(gè)msyql組
[root@VM_0_14_centos mysql]# cat /etc/passwd|grep mysql ---查看是否存在mysql用戶(hù)
[root@VM_0_14_centos mysql]# useradd -g mysql mysql ---新建msyql用戶(hù)
8押框、修改當(dāng)前目錄權(quán)限
[root@VM_0_14_centos mysql]# chown -R mysql:mysql /usr/local/mysql/
9理逊、初始化數(shù)據(jù)庫(kù)
[root@VM_0_14_centos bin]# ./mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
./mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory
若報(bào)如下錯(cuò)
./mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory
yun
安裝numactl
[root@VM_0_14_centos bin]# yum remove libnuma.so.1;
[root@VM_0_14_centos bin]# yum -y install numactl.x86_64
若報(bào)如下錯(cuò)
libaio.so.1: cannot open shared object file: No such file or directory
yun
安裝libaio
yum install libaio*
10、重新初始化成功骑歹,最后是初始化 root
登錄密碼
[root@VM_0_14_centos bin]# ./mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
2019-06-29T05:24:18.538969Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-06-29T05:24:19.722625Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-06-29T05:24:19.876417Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-06-29T05:24:19.979084Z 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: 257f6850-9a2e-11e9-9c9e-525400dc2e19.
2019-06-29T05:24:19.988044Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-06-29T05:24:19.988863Z 1 [Note] A temporary password is generated for root@localhost: 8w.9!6U4%m3
11、將 mysql
加入服務(wù)
[root@VM_0_14_centos bin]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
12墨微、配置my.cnf
搜索my.cnf
[root@VM_0_14_centos bin]# find / -name my.cnf
找到后復(fù)制到 /etc/my.cnf
并進(jìn)行如下編輯,若找不到則在/etc
下手動(dòng)編輯一個(gè)
[root@VM_0_14_centos bin]# vim /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
#不區(qū)分大小寫(xiě)
lower_case_table_names = 1
#不開(kāi)啟sql嚴(yán)格模式
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
13翘县、添加開(kāi)機(jī)啟動(dòng)修改basedir
和datadir
[root@VM_0_14_centos bin]# vi /etc/init.d/mysql
14谴分、開(kāi)機(jī)自啟
這里需要修改锈麸,Centos7變了
[root@VM_0_14_centos bin]# chkconfig --add mysql
[root@VM_0_14_centos bin]# chkconfig mysql on
15、啟動(dòng)mysql
服務(wù)
[root@VM_0_14_centos bin]# service mysql stop
ERROR! MySQL server PID file could not be found!
[root@VM_0_14_centos bin]# service mysql start
Starting MySQL. SUCCESS!
16牺蹄、查詢(xún)列表
[root@VM_0_14_centos bin]# chkconfig | grep -i mysql
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]'.
mysql 0:off 1:off 2:on 3:on 4:on 5:on 6:off
如果看到mysql的服務(wù)忘伞,并且3,4,5都是on的話則成功沙兰,如果是off,則執(zhí)行
[root@VM_0_14_centos bin]# chkconfig --level 345 mysql on
17鼎天、重啟電腦 reboot
,驗(yàn)證是否開(kāi)機(jī)自啟mysql服務(wù)
[root@VM_0_14_centos ~]# netstat -na | grep 3306
tcp6 0 0 :::3306 :::* LISTEN
18斋射、Mysq連接配置
連接Mysql
,使用root
賬號(hào)登錄【使用初始化時(shí)默認(rèn)密碼】
[root@VM_0_14_centos ~]# cd /usr/local/mysql/bin/
[root@VM_0_14_centos bin]# ./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.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>
19涧至、修改root
密碼
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> set PASSWORD = PASSWORD('1234567');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql>
20桑包、允許遠(yuǎn)程訪問(wèn)
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 host,user from user;
+-----------+---------------+
| host | user |
+-----------+---------------+
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
+-----------+---------------+
3 rows in set (0.00 sec)
mysql> create user 'root'@'%' identified by '1234567';
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql>
21、授權(quán)數(shù)據(jù)庫(kù)操作
mysql> grant all on finance.* to 'root'@'%' identified by '1234567' with grant option;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)