1.解压MySQL8.0.31压缩包
tar -xvf mysql-8.0.31-linux-glibc2.12-x86_64.tar.xz
2.重命名
mv mysql-8.0.31-linux-glibc2.12-x86_64.tar.xz/ mysql-8.0.31
3.复制到/usr/local
sudo mv mysql-8.0.31 /usr/local/
4.创建用户组
sudo groupadd mysql
5.添加用户
useradd -r -g mysql mysql
6.创建MySQL数据目录
mkdir -p /data
进入data目录
cd /data/
mkdir -p mysql
7.修改拥有者
chown mysql:mysql -R /data/mysql
8.生成编辑配置文件
vim /etc/my.cnf或sudo vim /etc/my.cnf
[mysqld]
bind-address=0.0.0.0
port=3306
user=mysql
basedir=/usr/local/mysql-8.0.31
datadir=/data/mysql
socket=/tmp/mysql.sock
log-error=/data/mysql/mysql.err
pid-file=/data/mysql/mysql.pid
#character config
character_set_server=utf8mb4
symbolic-links=0
9.初始化MYSQL
cd /usr/local/mysql-8.0.31/bin/
./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql-8.0.31/ --datadir=/data/mysql/ --user=mysql --initialize
或
sudo ./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql-8.0.31/ --datadir=/data/mysql/ --user=mysql --initialize
10.查看MySQL初始密码
cat /data/mysql/mysql.err
11.启动mysql
cp /usr/local/mysql-8.0.31/support-files/mysql.server /etc/init.d/mysql
/etc/init.d/mysql status
启动 service mysql start
查看状态 service mysql status
12.修改mysql密码
cd /usr/local/mysql-8.0.31/bin/
./mysql -u root -p
ALTER USER ‘root’@‘localhost’ IDENTIFIED WITH mysql_native_password BY ‘cyroot’;
13.修改 vi /etc/my.cnf(注意修改前先停止服务service mysql stop)
default-storage-engine=INNODB
performance_schema=off
table_open_cache=128
transaction_isolation=READ-COMMITTED
max_connections=1000
max_connect_errors=6000
max_allowed_packet=64M
innodb_file_per_table=1
innodb_buffer_pool_size=512M
innodb_flush_method=O_DIRECT
innodb_lock_wait_timeout=1800
server-id=1
log-bin=mysql-bin
expire_logs_days = 2
binlog_format=mixed
character-set-client-handshake = FALSE
character-set-server=utf8mb4
collation-server=utf8mb4_general_ci
init_connect='SET default_collation_for_utf8mb4=utf8mb4_general_ci'
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
skip-name-resolve
[mysql]
default-character-set=utf8mb4
[mysql.server]
default-character-set=utf8mb4
14.开启MySQL远程权限
#连接数据库
cd /usr/local/mysql-8.0.31/bin/
./mysql -u root -p
#使用mysql数据库
use mysql;
#查询所有用户
select User,Host from user;
±-----------------±----------+
| User | Host |
±-----------------±----------+
| mysql.infoschema | localhost |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
±-----------------±----------+
#更新root的host %允许所有IP连接
update user set host = ‘%’ where user = ‘root’;
#查看更新结果
select User,Host from user;
±-----------------±----------+
| User | Host |
±-----------------±----------+
| root | % |
| mysql.infoschema | localhost |
| mysql.session | localhost |
| mysql.sys | localhost |
±-----------------±----------+
#刷新权限立即生效
flush privileges;
15.创建metersphere数据库
CREATE DATABASE metersphere
16.配置MySQL全局变量
进入mysql安装目录下bin目录
/usr/local/mysql-8.0.31/bin
打开全局变量文件
vim /etc/profile
全局变量文件最后一行增加
export PATH=$PATH:/usr/local/mysql-8.0.31/bin
重新加载变量文件
source /etc/profile文章来源:https://www.toymoban.com/news/detail-418799.html
测试----输入mysql -uroot -p密码文章来源地址https://www.toymoban.com/news/detail-418799.html
到了这里,关于统信UOS安装Mysql的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!