- 参考资料
- MySQL安装
- 1.Linux 安装
- 1.1 mysql-8.0.26版本
- 1.2 安装步骤
- 1.2.1 安装依赖包
- 1.2.2 创建 mysql 用户和用户组
- 1.2.3 解压 mysql-8.0.26-linux-glibc2.17-x86_64-minimal-rebuild.tar.xz
- 1.2.4 切换到 /usr/local
- 1.2.5 将 /opt/mysql/mysql-8.0.26/ 软链到 /usr/local/mysql
- 1.2.6 切换到 /usr/local/mysql,并创建 mysql-files文件夹
- 1.2.7 初始化 mysql 数据目录
- 1.2.8 mysqld_safe启动 mysql 服务
- 1.2.9 验证
- 1.2.10 MySQL workbench 连接数据库
- 1.3 mysql-5.6.51 版本
- 2.windows 安装
- 1.Linux 安装
- 其他
参考资料
MySQL安装
1.Linux 安装
1.1 mysql-8.0.26版本
官方文档安装说明:https://dev.mysql.com/doc/refman/8.0/en/linux-installation.html
个人习惯使用压缩包版本的,官方压缩包版本的安装说明文档:https://dev.mysql.com/doc/refman/8.0/en/binary-installation.html
下载地址:https://downloads.mysql.com/archives/community/
我这里选择 mysql-8.0.26-linux-glibc2.17-x86_64-minimal-rebuild.tar.xz 版本的mysql。
查看 glibc 版本命令: rpm -qa | grep glibc
如果之前安装过mysql 一定要确保安装的文件删除掉。注意需要删除 /etc/my.cnf 或者/etc/mysql 路径下的启动选项文件。
1.2 安装步骤
1.2.1 安装依赖包
(1)libaio
# 查找安装包
yum search libaio
# 安装 libaio
yum install libaio
(2)ncurses-compat-libs
mysql-VERSION-el7-x86_64.tar.gz 和 mysql-VERSION-linux-glibc2.12-x86_64.tar.xz 没有安装 lib64/libtinfo.so.5,所以需要手动安装
yum install ncurses-compat-libs
1.2.2 创建 mysql 用户和用户组
# 添加 mysql 用户组
groupadd mysql
# 添加 mysql 用户(没有实际登录权限的用户,仅用于安装mysql使用)
# -r 创建一个系统账户
# -g 指定哪个用户组
# -s 用户登录的shell名
useradd -r -g mysql -s /bin/false mysql
1.2.3 解压 mysql-8.0.26-linux-glibc2.17-x86_64-minimal-rebuild.tar.xz
(1)将mysql-8.0.26-linux-glibc2.17-x86_64-minimal-rebuild.tar.xz 上传到服务器 /opt/mysql 路径下(路径你可以自己定义)。
(2)解压 mysql-8.0.26-linux-glibc2.17-x86_64-minimal-rebuild.tar.xz
# 切换到上传目录下
cd /opt/mysql/
# 解压压缩包
xz -d mysql-8.0.26-linux-glibc2.17-x86_64-minimal-rebuild.tar.xz
tar -xvf mysql-8.0.26-linux-glibc2.17-x86_64-minimal-rebuild.tar
# 重命名解压后文件夹
mv mysql-8.0.26-linux-glibc2.17-x86_64-minimal-rebuild mysql-8.0.26
1.2.4 切换到 /usr/local
cd /usr/local/
1.2.5 将 /opt/mysql/mysql-8.0.26/ 软链到 /usr/local/mysql
ln -s /opt/mysql/mysql-8.0.26/ mysql
1.2.6 切换到 /usr/local/mysql,并创建 mysql-files文件夹
cd mysql
# 其实在 /opt/mysql/mysql-8.0.26/下创建 mysql-files
mkdir mysql-files
# 将 mysql-files所有权赋给 mysql用户
chown mysql:mysql mysql-files
# 修改权限
chmod 750 mysql-files
1.2.7 初始化 mysql 数据目录
# 初始化数据目录,完成后安装目录下多了一个 data 文件夹。
bin/mysqld --initialize --user=mysql
bin/mysql_ssl_rsa_setup
注意:一定要记住这个临时密码。
1.2.8 mysqld_safe启动 mysql 服务
bin/mysqld_safe --user=mysql &
Ctrl + c 取消后,进行验证。
1.2.9 验证
(1) 查看 mysql 进程
ps -ef|grep mysql
(2)查看启动错误日志
cat /usr/local/mysql/data/192.168.188.134.err
(3) bin/mysqladmin 验证
bin/mysqladmin -u root -p version
Enter password: (enter root password here)
但是报错:
改为 私用 mysql 连接数据库
bin/mysql -u root -p
登录成功。修改root密码:
ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码';
退出,重新登录后查看数据库:
再次使用bin/mysqladmin version验证:
bin/mysqladmin -u root -p version
Enter password: (enter root password here)
1.2.10 MySQL workbench 连接数据库
(1)报错:无法连接服务器
解决方案:
可参考 《无法访问 CentOS7服务器上应用监听的端口》开启防火墙端口。
(2)使用root连接报错
参考 《centos7 打开mysql 3306端口并设置外部访问》centos7 打开mysql 3306端口并 设置外部访问
解决方法:
# 服务器使用root登录
/usr/local/mysql/bin/mysql -u root -p
# 输入密码,按回车
# 新增普通用户black(注意 一定是%而不是localhost,如果是localhost则只能本地访问)
create user 'black'@'%' identified by 'black';
# 给付权限
grant select,insert,update,delete,create,drop,alter,INDEX on *.* to 'black'@'%' ;
或
grant all privileges on *.* to 'black'@'%' with grant option;
# 刷新权限
flush privileges;
给用户赋权限,参考
https://www.cnblogs.com/xiaofengchu/p/8416173.html
使用 black 用户连接成功:
1.3 mysql-5.6.51 版本
这里我使用二进制压缩包安装mysql。
官方安装文档:https://dev.mysql.com/doc/refman/5.6/en/binary-installation.html
1.3.1 安装依赖
mysql 依赖两个包:
- libaio
- libtinfo.so.5 (从MySQL 5.6.37版本开始bin/mysql依赖 此库)
(1)libaio
CentOS 安装 libaio:
# 查找安装包
yum search libaio
# 安装 libaio
yum install libaio
Ubuntu 安装 libaio:
sudo apt-cache search libaio # search for info
sudo apt-get install libaio1 # install library
(2)libtinfo.so.5
如果没有安装 lib64/libtinfo.so.5,那么需要手动安装:
CentOS 安装命令
yum install ncurses-compat-libs
Ubuntu 安装命令
apt-get install libtinfo5
1.3.2 添加 mysql 用户和用户组
# 添加 mysql 用户组
groupadd mysql
# 添加 mysql 用户(没有实际登录权限的用户,仅用于安装mysql使用)
# -r 创建一个系统账户
# -g 指定哪个用户组
# -s 用户登录的shell名
useradd -r -g mysql -s /bin/false mysql
1.3.3 解压 mysql-5.6.51-linux-glibc2.12-x86_64.tar.gz
tar -zxvf mysql-5.6.51-linux-glibc2.12-x86_64.tar.gz -C /home/soft/
1.3.4 软链到 /usr/local/mysql
ln -s /home/soft/mysql-5.6.51-linux-glibc2.12-x86_64 /usr/local/mysql
1.3.5 添加mysql/bin到PATH变量中
使用vi /etc/profile
命令,在文件末尾添加如下:
# set mysql bin
MYSQL_HOME=/usr/local/mysql
PATH=$PATH:$MYSQL_HOME/bin:
export PATH
添加完成后,:wq
保存退出。
使用 source /etc/profile
命令使配置生效。
echo $PATH
可进行验证
1.3.6 初始化数据库数据文件目录
# 1. 切换到mysql安装目录/usr/local/mysql(即 /home/soft/mysql-5.6.51-linux-glibc2.12-x86_64/)
cd /usr/local/mysql
# 2.使用 mysql 用户执行mysql_install_db进行数据目录初始化(仅在第一次安装时进行此操作)
# 该脚本会创建2个数据库数据:mysql 和 test。 --basedir指定mysql安装目录; --datadir 指定了数据库数据存储路径
scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
控制台打印内容
root@iZ2zej1kjdqmvll88o5w0qZ:/usr/local/mysql# scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
Installing MySQL system tables...2023-02-12 13:29:54 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2023-02-12 13:29:54 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2023-02-12 13:29:54 0 [Note] /usr/local/mysql/bin/mysqld (mysqld 5.6.51) starting as process 361503 ...
2023-02-12 13:29:54 361503 [Note] InnoDB: Using atomics to ref count buffer pool pages
2023-02-12 13:29:54 361503 [Note] InnoDB: The InnoDB memory heap is disabled
2023-02-12 13:29:54 361503 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2023-02-12 13:29:54 361503 [Note] InnoDB: Memory barrier is not used
2023-02-12 13:29:54 361503 [Note] InnoDB: Compressed tables use zlib 1.2.11
2023-02-12 13:29:54 361503 [Note] InnoDB: Using Linux native AIO
2023-02-12 13:29:54 361503 [Note] InnoDB: Using CPU crc32 instructions
2023-02-12 13:29:54 361503 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2023-02-12 13:29:54 361503 [Note] InnoDB: Completed initialization of buffer pool
2023-02-12 13:29:54 361503 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2023-02-12 13:29:54 361503 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2023-02-12 13:29:54 361503 [Note] InnoDB: Database physically writes the file full: wait...
2023-02-12 13:29:54 361503 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2023-02-12 13:29:54 361503 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2023-02-12 13:29:55 361503 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2023-02-12 13:29:55 361503 [Warning] InnoDB: New log files created, LSN=45781
2023-02-12 13:29:55 361503 [Note] InnoDB: Doublewrite buffer not found: creating new
2023-02-12 13:29:55 361503 [Note] InnoDB: Doublewrite buffer created
2023-02-12 13:29:55 361503 [Note] InnoDB: 128 rollback segment(s) are active.
2023-02-12 13:29:55 361503 [Warning] InnoDB: Creating foreign key constraint system tables.
2023-02-12 13:29:55 361503 [Note] InnoDB: Foreign key constraint system tables created
2023-02-12 13:29:55 361503 [Note] InnoDB: Creating tablespace and datafile system tables.
2023-02-12 13:29:55 361503 [Note] InnoDB: Tablespace and datafile system tables created.
2023-02-12 13:29:55 361503 [Note] InnoDB: Waiting for purge to start
2023-02-12 13:29:55 361503 [Note] InnoDB: 5.6.51 started; log sequence number 0
2023-02-12 13:29:55 361503 [Note] RSA private key file not found: /usr/local/mysql/data//private_key.pem. Some authentication plugins will not work.
2023-02-12 13:29:55 361503 [Note] RSA public key file not found: /usr/local/mysql/data//public_key.pem. Some authentication plugins will not work.
2023-02-12 13:29:55 361503 [Note] Binlog end
2023-02-12 13:29:55 361503 [Note] InnoDB: FTS optimize thread exiting.
2023-02-12 13:29:55 361503 [Note] InnoDB: Starting shutdown...
2023-02-12 13:29:57 361503 [Note] InnoDB: Shutdown completed; log sequence number 1625977
OK
Filling help tables...2023-02-12 13:29:57 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2023-02-12 13:29:57 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2023-02-12 13:29:57 0 [Note] /usr/local/mysql/bin/mysqld (mysqld 5.6.51) starting as process 361562 ...
2023-02-12 13:29:57 361562 [Note] InnoDB: Using atomics to ref count buffer pool pages
2023-02-12 13:29:57 361562 [Note] InnoDB: The InnoDB memory heap is disabled
2023-02-12 13:29:57 361562 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2023-02-12 13:29:57 361562 [Note] InnoDB: Memory barrier is not used
2023-02-12 13:29:57 361562 [Note] InnoDB: Compressed tables use zlib 1.2.11
2023-02-12 13:29:57 361562 [Note] InnoDB: Using Linux native AIO
2023-02-12 13:29:57 361562 [Note] InnoDB: Using CPU crc32 instructions
2023-02-12 13:29:57 361562 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2023-02-12 13:29:57 361562 [Note] InnoDB: Completed initialization of buffer pool
2023-02-12 13:29:57 361562 [Note] InnoDB: Highest supported file format is Barracuda.
2023-02-12 13:29:57 361562 [Note] InnoDB: 128 rollback segment(s) are active.
2023-02-12 13:29:57 361562 [Note] InnoDB: Waiting for purge to start
2023-02-12 13:29:57 361562 [Note] InnoDB: 5.6.51 started; log sequence number 1625977
2023-02-12 13:29:57 361562 [Note] RSA private key file not found: /usr/local/mysql/data//private_key.pem. Some authentication plugins will not work.
2023-02-12 13:29:57 361562 [Note] RSA public key file not found: /usr/local/mysql/data//public_key.pem. Some authentication plugins will not work.
2023-02-12 13:29:57 361562 [Note] Binlog end
2023-02-12 13:29:57 361562 [Note] InnoDB: FTS optimize thread exiting.
2023-02-12 13:29:57 361562 [Note] InnoDB: Starting shutdown...
2023-02-12 13:29:59 361562 [Note] InnoDB: Shutdown completed; log sequence number 1625987
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/local/mysql/bin/mysqladmin -u root password 'new-password'
/usr/local/mysql/bin/mysqladmin -u root -h iZ2zej1kjdqmvll88o5w0qZ password 'new-password'
Alternatively you can run:
/usr/local/mysql/bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
cd . ; /usr/local/mysql/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd mysql-test ; perl mysql-test-run.pl
Please report any problems at http://bugs.mysql.com/
The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
WARNING: Found existing config file /usr/local/mysql/my.cnf on the system.
Because this file might be in use, it was not replaced,
but was used in bootstrap (unless you used --defaults-file)
and when you later start the server.
The new default config file was created as /usr/local/mysql/my-new.cnf,
please compare it with your file and take the changes you need.
WARNING: Default config file /etc/mysql/my.cnf exists on the system
This file will be read by default by the MySQL server
If you do not want to use this, either remove it, or use the
--defaults-file argument to mysqld_safe when starting the server
1.3.7 添加选项文件
不同的启动命令支持选项文件里的分组
启动脚本 | 选项文件内的分组 |
---|---|
mysqld | [mysqld], [server], [mysqld-major_version] |
mysqld_safe | [mysqld], [server], [mysqld_safe] |
mysql.server | [mysqld], [mysql.server], [server] |
Linux 环境读取的选项文件:
文件名(优先级由上到下) | 用途 |
---|---|
/etc/my.cnf | 全局选项 |
/etc/mysql/my.cnf | 全局选项 |
SYSCONFDIR/my.cnf | 全局选项(SYSCONFDIR 表示 CMake 指令构建 mysql时指定的参数) |
$MYSQL_HOME/my.cnf | 服务器级别的选项 |
defaults-extra-file | --defaults-extra-file 指定的文件 |
用户目录/.my.cnf | 用户声明的选项 |
用户目录/.mylogin.cnf | 用户声明的登录路径选项 (仅客户端使用) |
该步骤可跳过,按文档中说明可自动加载 $MYSQL_HOME/my.cnf 选项配置文件;如有需要指定,则可自行调整
编辑 /usr/local/mysql/my.cnf 选项配置文件,添加以下内容:
[mysqld]
# 设置时区(东8区)
default-time_zone=+8:00
# 设置默认数据库引擎(InnoDB)
default_storage_engine=InnoDB
# 设置数据库编码和排序
character_set_server=utf8mb4
collation_server=utf8mb4_general_ci
选项文件可配置选项可参看:https://dev.mysql.com/doc/refman/5.6/en/server-option-variable-reference.html
1.3.8 配置自动启停 mysql 服务
参考文档:https://dev.mysql.com/doc/refman/5.6/en/automatic-start.html
启动 mysql 服务方式:
- 使用 mysqld (任何平台都生效)
- mysqld_safe(官方推荐)
- mysql.server
通过 mysql.server 脚本可实现系统启动时MySQL服务自启动
cd /usr/local/mysql
cp support-files/mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql
1.3.9 启动 mysql 服务
cd /usr/local/mysql/
# 使用非 root 用户启动mysql(一定得后台运行,否则窗口会卡住一直等待)
./bin/mysqld_safe --user=mysql &
停止mysql服务命令: mysqladmin shutdown
1.3.10 验证服务启动情况
cd /usr/local/mysql
bin/mysqladmin version
控制台输出:
bin/mysqladmin Ver 8.42 Distrib 5.6.51, for linux-glibc2.12 on x86_64
Copyright (c) 2000, 2021, 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.
Server version 5.6.51
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /tmp/mysql.sock
Uptime: 1 min 45 sec
Threads: 1 Questions: 2 Slow queries: 0 Opens: 67 Flush tables: 1 Open tables: 60 Queries per second avg: 0.019
1.3.11 设置 root 用户密码
更新用户名密码有3种方式:
- SET PASSWORD 语句
- UPDATE 语句
- mysqladmin 工具设置
SET PASSWORD 语句
$> mysql -u root
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('new_password');
mysql> SET PASSWORD FOR 'root'@'127.0.0.1' = PASSWORD('new_password');
mysql> SET PASSWORD FOR 'root'@'::1' = PASSWORD('new_password');
mysql> SET PASSWORD FOR 'root'@'host_name' = PASSWORD('new_password');
UPDATE 语句
$> mysql -u root
mysql> UPDATE mysql.user SET Password = PASSWORD('new_password')
-> WHERE User = 'root';
mysql> FLUSH PRIVILEGES;
mysqladmin
$> mysqladmin -u root -p shutdown
Enter password: (enter root password here)
这里我选择,SET PASSWORD 语句方式设置 root 用户密码:
(1) 连接数据库
mysql -u root
(2)设置 root 用户密码
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('new_password');
(3) 使用 root 登录并查看数据库
# 连接数据库
mysql -u root -p
# 查看数据库
show databases;
其实至此,mysql 数据库已经安装完成了。后续的步骤就是新建数据库-用户-授权-表,如果不需要可跳过不做
1.3.12 新建数据库、用户、授权、表(可跳过)
(1)登录服务器
mysql -u root -p
(2)创建“blackdb”数据库
create database if not exists blackdb;
(3)创建 black 用户(%表示任何域名)
create user 'black'@'%' identified by 'black';
(4)授权数据库 blackdb 给 black 用户
-- 将数据库 blackdb 授权给 black 用户
gant * on blackdb.* to 'black'@'%';
-- 刷新权限
flush privileges;
(5)测试
(6)完成。
2.windows 安装
2.1 下载 mysql-8.0.26-winx64.zip 并解压
将下载的 mysql-8.0.26-winx64.zip 解压到 e:\work\software下
2.2 初始化数据目录
因为压缩包版本没有自带数据目录,所以安装前需要初始化数据目录。
- 在 E:\work\software\mysql-8.0.26-winx64 下创建 data 文件夹。
- 使用
mysqld.exe --initialize
进行数据目录初始化
# 进入 mysql-8.0.26 安装目录下的 bin 目录
cd E:\work\software\mysql-8.0.26-winx64\bin
# 初始化数据目录 (basedir 指定的是mysql 安装目录,datadir指定数据文件存放路径)
mysqld.exe --initialize --console --basedir=E:\work\software\mysql-8.0.26-winx64 --datadir=E:\work\software\mysql-8.0.26-winx64\data
还可以通过配置文件进行初始化:
- 在 E:\work\software\mysql-8.0.26-winx64 下创建一个名字为 mysql.ini 文件,内容如下:
[mysqld]
basedir=E:\\work\\software\\mysql-8.0.26-winx64
datadir=E:\\work\\software\\mysql-8.0.26-winx64\\data
- 初始化数据目录
# defaults-file 必须紧跟 mysqld.exe
mysqld.exe --defaults-file=E:\work\software\mysql-8.0.26-winx64\mysql.ini --initialize --console
注意: 通过
--initialize
初始化时会给 root 用户生成随机密码(有过期时间)。
初始化完成后,
- mysql会在数据目录下创建
mysql
系统数据库和它的表 - server 会初始化系统表空间和相关的数据结构。
- 创建 root@localhost 用户
执行初始化命令:
命令执行完成后,data 目录下的内容:
查看 SC-202108201319.err 内容获取 root用户随机密码:
2.3 启动 mysql
启动命令:
cd E:\work\software\mysql-8.0.26-winx64\bin
# defaults-file 必须紧跟 mysqld.exe
mysqld.exe --defaults-file=E:\work\software\mysql-8.0.26-winx64\mysql.ini --console
保持此CMD窗口不动,再开启 CMD 窗口,使用mysql.exe -u root -p
连接 mysql:
注意: root 用户的密码是 SC-202108201319.err 里打印的,由于很复杂,避免输入错误,可以复制粘贴过来。
2.4 修改 root 用户密码
使用 mysql.exe -u root -p --default-character-set=utf8mb4
连接 mysql后,输入以下语句修改 root 用户密码:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
注意:此 root 用户只能通过命令行连接登陆,如果需要远程连接则需要在创建用户时将主机换成'%'或者具体IP:
# 创建一个可以远程连接的用户 black
create user 'black'@'%' identified by 'black';
2.5 将 mysql 作为 window 服务启动
问题:
注意,前面启动 mysql 后必须保证CMD窗口一直打开,mysql 服务才可以一直运行,这样可不行!
解决方案:
- 启动命令加上
-d
参数,即可后台运行 - 将 mysql 作为 window 服务可解决。
参考官方文档: 作为 window 服务启动,
cd E:\work\software\mysql-8.0.26-winx64\bin
# 注册服务名为 mysql8
mysqld.exe --install mysql8 --defaults-file=E:\work\software\mysql-8.0.26-winx64\mysql.ini
# 启动 mysql8 服务
net start mysql8
停止服务命令:
net stop mysql8
移除服务命令:
mysqld.exe --remove mysql8
2.6 添加自定义用户
- 创建 black 用户
create user 'black'@'%' identified by 'black';
grant ALTER,CREATE,DROP,INSERT,SELECT,UPDATE,DELETE,INDEX,REFERENCES,PROCESS,SHOW DATABASES,TRIGGER,LOCK TABLES,GRANT OPTION ON *.* to 'black'@'%';
- 刷新授权
FLUSH PRIVILEGES;
2.7 测试
在命令行使用 black 登录,并查看有哪些数据库:
创建 blackdb 数据库:
create database blackdb;
使用 DBeaver 连接测试
至此,mysql 8.0.26 安装完成。
2.8 设置字符集
查看当前的字符集设置:
SHOW VARIABLES LIKE 'character_set%';
- 通过
set names
命令动态设置字符集
set names 'utf8mb4'
set names
等同于
SET character_set_client = charset_name;
SET character_set_results = charset_name;
SET character_set_connection = charset_name;
character_set_client,character_set_results,character_set_connection可通过
mysql.exe -u root -p --default-character-set=utf8mb4
修改。
- mysql.ini 文件添加:
[mysqld]
character-set-server=utf8mb4
collation-server=utf8mb4_0900_ai_ci
其他
mysql 读取配置文件顺序:
修改时区
查看时区:
show variables like "%time_zone%";
- mysql.ini 添加:
[mysqld]
default-time_zone=+8:00
- 命令设置
# 设置东八区
set global time_zone = '+8:00';
set time_zone = '+8:00';
flush privileges;
本文来自博客园,作者:不安分的黑娃,转载请注明原文链接:https://www.cnblogs.com/lihw-study/p/15511141.html