mysql8.0安装

2023-12-26 15:31:14

mysql8.0安装

yum安装

# 下载和安装
wget http://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
rpm -ivh mysql80-community-release-el7-3.noarch.rpm
yum install mysql-community-server -y
grep 'temporary password' /var/log/mysqld.log    查看密码


set global validate_password.policy=0;			
set global validate_password.length=1;    修改密码长度和规则
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';  修改密码为123456
update mysql.user set host='%' where user="root";  修改root可以远程访问
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456'; 
grant system_user on *.* to 'root';
flush privileges;

ALTER USER 'root'@'%' IDENTIFIED BY '123456' PASSWORD EXPIRE NEVER;
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
FLUSH PRIVILEGES;


docker-compose安装

version: "3"
services:
  mysql:
    container_name: mysql
    image: mysql:latest
    restart: always 
    ports:
      - 3306:3306          
    environment:
      MYSQL_ROOT_PASSWORD: AAAaaa111.
    volumes:
      - /root/mysql/conf/:/etc/mysql/
      - /root/mysql/mysql_data/:/var/lib/mysql/
    networks:
    - test_net
#########################################
networks:
  test_net:
    name: test_net
    driver: bridge
    ipam:
      config:
      - subnet: "172.200.0.0/16"

源码安装

#源码安装MYSQL 8.0.28方法,通过cmake、make、make install三个步骤实现。 
#下载MYSQL 8.0版本;
https://mirror.tuna.tsinghua.edu.cn/mysql/downloads/MySQL-8.0/mysql-boost-8.0.28.tar.gz
#安装高版本GCC源;
yum -y install centos-release-scl
#安装依赖包和库文件;
yum -y install ncurses-devel make perl gcc autoconf automake zlib libxml2 libxml2-devel libgcrypt libtool bison devtoolset-10-gcc devtoolset-10-gcc-c++ devtoolset-10-binutils openssl openssl-devel
#启用新版Gcc;
scl enable devtoolset-10 bash
#解压MYSQL8.x软件包;
tar xzf mysql-boost-8.0.28.tar.gz
#进入MYSQL8.x源代码目录;
cd mysql-8.0.28/
#预编译;
cmake  .  -DCMAKE_INSTALL_PREFIX=/usr/local/mysql/ \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DMYSQL_DATADIR=/data/mysql/ \
-DSYSCONFDIR=/etc \
-DMYSQL_USER=mysql \
-DMYSQL_TCP_PORT=3306 \
-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 \
-DWITH_BOOST=./boost/ \
-DFORCE_INSOURCE_BUILD=1
#编译;
make -j4
#安装;
make -j4 install
#初始化MYSQL数据库;
/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql/ --datadir=/data/mysql/
#设置MYSQL为系统服务;
ln -s /usr/local/mysql/bin/* /usr/bin/
\cp support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
/etc/init.d/mysqld start
#默认源码安装初始化MYSQL没有密码,直接进入数据库;
mysql
#修改密码规则和长度限制;
set global validate_password.policy=0;
set global validate_password.length=1;
#修改密码为123456,指令如下;
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
#默认root用户不能远程登录,需要更新密码信息;
update mysql.user set host='%' where user="root";
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
grant system_user on *.* to 'root';
flush privileges;
#修改root密码,命令如下;
update user set authentication_string=password("root") where user='root' and host='localhost';
#mysql8.0之前的版本中加密规则是mysql_native_password, 而在mysql8之后,加密规则是caching_sha2_password
#如果使用Navicat进行mysql登录时出现弹窗报错,需执行以下指令:
grant system_user on *.* to 'root';
ALTER USER 'root'@'%' IDENTIFIED BY '123456' PASSWORD EXPIRE NEVER;
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
FLUSH PRIVILEGES;



文章来源:https://blog.csdn.net/xiaolong1155/article/details/135221904
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。