MySQL安装
一、yum安装mariadb
1、配置yum源
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# vim mariadb.repo
[mariadb]
name = MariaDB
baseurl = https://mirrors.nju.edu.cn/mariadb/yum/10.2/centos7-amd64
gpgkey=https://mirrors.nju.edu.cn/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck=1
安装mariadb
[root@localhost ~]# yum -y install mariadb mariadb-server mariadb-devel
查看安装情况
[root@localhost ~]# rpm -qa|grep mariadb
mariadb-libs-5.5.60-1.el7_5.x86_64
mariadb-server-5.5.60-1.el7_5.x86_64
mariadb-5.5.60-1.el7_5.x86_64
mariadb-devel-5.5.60-1.el7_5.x86_64
二、源码部署mysql5.7
安装boost库
[root@localhost ~]# tar xf boost_1_59_0.tar.gz
[root@localhost ~]# mv boost_1_59_0 /usr/local/boost
安装mysql5.7
[root@localhost ~]# tar xf mysql-5.7.21.tar.gz
[root@localhost ~]# cd mysql-5.7.21
安装依赖包
[root@localhost mysql-5.7.21]# yum -y install gcc gcc-c++ ncurses-devel libaio bison git cmake openssl-devel
预编译
[root@localhost mysql-5.7.21]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql57 -DMYSQL_UNIX_ADDR=/data/mysql57/mysql.sock -DMYSQL_DATADIR=/data/mysql57 -DSYSCONFDIR=/usr/local/mysql57 -DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3307 -DWITH_XTRADB_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DWITH_EXTRA_CHARSETS=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DWITH_BIG_TABLES=1 -DWITH_DEBUG=0 -DENABLE_DTRACE=0 -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost
编译安装mysql5.7
[root@localhost mysql-5.7.21]# make && make install
[root@localhost mysql-5.7.21]# mkdir -p /data/mysql57
[root@localhost mysql-5.7.21]# useradd -s /sbin/nologin mysql
[root@localhost mysql-5.7.21]# chown -R mysql. /data/mysql57
[root@localhost mysql-5.7.21]# cp support-files/mysql.server /etc/init.d/mysqld57
[root@localhost mysql-5.7.21]# chmod +x /etc/init.d/mysqld57
[root@localhost mysql-5.7.21]# vim /usr/local/mysql57/my.cnf
[mysqld]
basedir=/usr/local/mysql57/
datadir=/data/mysql57/
port=3307
pid-file=/data/mysql57/mysql.pid
socket=/tmp/mysql.sock
[mysqld_safe]
log-error=/data/mysql57/mysql.log
初始化数据库
[root@localhost mysql-5.7.21]# /usr/local/mysql57/bin/mysqld --initialize --user=mysql --datadir=/data/mysql57 --basedir=/usr/local/mysql57
[root@localhost mysql-5.7.21]# ls /data/mysql57/
auto.cnf ib_buffer_pool ibdata1 ib_logfile0 ib_logfile1 mysql performance_schema sys
启动mysql服务
[root@localhost mysql-5.7.21]# /etc/init.d/mysqld57 start
[root@localhost mysql-5.7.21]# vim /usr/local/mysql57/my.cnf
skip-grant-tables
[root@localhost mysql-5.7.21]# /etc/init.d/mysqld57 restart
[root@localhost mysql-5.7.21]# ln -s /tmp/mysql.sock /data/mysql57/mysql.sock
[root@localhost mysql-5.7.21]# /usr/local/mysql57/bin/mysql
mysql> update mysql.user set authentication_string=password('') where user="root";
[root@localhost mysql-5.7.21]# /etc/init.d/mysqld57 restart
免密码登录
[root@localhost mysql-5.7.21]# /usr/local/mysql57/bin/mysql
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 2
Server version: 5.7.21 Source distribution
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>
三、二进制部署部署mysql8.0
1、安装依赖包
[root@localhost yum.repos.d]# yum -y install gcc gcc-c++ ncurses-devel libaio bison git cmake openssl-devel
2、解压缩
[root@localhost ~]# tar -xf mysql-8.0.24-el7-x86_64.tar.gz
[root@localhost ~]# cd /usr/local/mysql/
3、移动安装文件到/usr/local/mysql 下
[root@localhost ~]# mv mysql-8.0.24-el7-x86_64 /usr/local/mysql
[root@localhost ~]# cd /usr/local/mysql/
4、创建mysql用户和组
[root@localhost mysql]# useradd -s /sbin/nologin mysql
5、创建数据目录
[root@localhost mysql]# mkdir -p /data/mysql
6、变更数据目录为mysql用户所属主和所属组
[root@localhost mysql]# chown -R mysql. /data/mysql
7、将启动文件移动到启动目录下,并给予执行权限
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql]# chmod +x /etc/init.d/mysqld
8、编辑mysql配置文件
[root@localhost mysql]# vim /usr/local/mysql/my.cnf
[mysqld]
basedir=/usr/local/mysql/
datadir=/data/mysql/
port=3306
pid-file=/data/mysql/mysql.pid
socket=/data/mysql/mysql.sock
[mysqld_safe]
log-error=/data/mysql/mysql.log
9、初始化
[root@localhost mysql]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/data/mysql --basedir=/usr/local/mysql
[root@localhost mysql]# ls /data/mysql/
auto.cnf client-cert.pem #ib_16384_1.dblwr ib_logfile0 mysql private_key.pem server-key.pem undo_002
ca-key.pem client-key.pem ib_buffer_pool ib_logfile1 mysql.ibd public_key.pem sys
ca.pem #ib_16384_0.dblwr ibdata1 #innodb_temp performance_schema server-cert.pem undo_001
10、设置启动文件链接
[root@localhost mysql]# ln -s /usr/local/mysql/bin/* /usr/local/bin
11、启动mysql服务,查看服务的运行情况
[root@localhost mysql]# /etc/init.d/mysqld start
Starting MySQL.Logging to '/data/mysql/mysql.log'.
.... SUCCESS!
[root@localhost mysql]# ps -ef |grep mysql
root 4184 1 0 05:02 pts/0 00:00:00 /bin/sh /usr/local/mysql//bin/mysqld_safe --datadir=/data/mysql/ --pid-file=/data/mysql/mysql.pid
mysql 4349 4184 10 05:02 pts/0 00:00:02 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql/ --datadir=/data/mysql --plugin-dir=/usr/local/mysql//lib/plugin --user=mysql --log-error=/data/mysql/mysql.log --pid-file=/data/mysql/mysql.pid --socket=/data/mysql/mysql.sock --port=3306
root 4402 1478 0 05:03 pts/0 00:00:00 grep --color=auto mysql
[root@localhost mysql]# netstat -anptul|grep :3306
tcp6 0 0 :::33060 :::* LISTEN 4349/mysqld
tcp6 0 0 :::3306 :::* LISTEN 4349/mysqld
连接出现错误
[root@localhost mysql]# mysql -uroot -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
[root@localhost ~]# ln -s /data/mysql/mysql.sock /tmp/
[root@localhost ~]# /usr/local/mysql/bin/mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@localhost ~]# /usr/local/mysql/bin/mysql -uroot –p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
修改登录密码
[root@localhost ~]# vim /usr/local/mysql/my.cnf
skip-grant-tables
[root@localhost ~]# /etc/init.d/mysqld restart
[root@localhost ~]# /usr/local/mysql/bin/mysql
mysql> select host, user, authentication_string, plugin from mysql.user;
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
| host | user | authentication_string | plugin |
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
| localhost | mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | mysql.session | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | mysql.sys | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | root | $A$005$
;
j;D?z47X*YB!jeDFujaez6PRCqAwu2bGrt2rlTKxyhbRiJRR59cbVCGt8 | caching_sha2_password |
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
4 rows in set (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql> alter user 'root'@'localhost'IDENTIFIED BY '123';
Query OK, 0 rows affected (0.01 sec)
修改配置,重启服务,重新登录
[root@localhost ~]# vim /usr/local/mysql/my.cnf
删除掉skip-grant-tables
[root@localhost ~]# /etc/init.d/mysqld restart
Shutting down MySQL. SUCCESS!
Starting MySQL. SUCCESS!
[root@localhost ~]# /usr/local/mysql/bin/mysql -uroot -p123
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 8
Server version: 8.0.24 MySQL Community Server - GPL
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
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>
本文摘自 :https://www.cnblogs.com/