赞
踩
mysql官网网址:MySQL
1.4.1 Linux中下载MySQL
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.30-linux-glibc2.12-x86_64.tar.xz
1.6.1 首先要将mysql包移动到到自定义的安装目录下
mv mysql-8.0.30-linux-glibc2.12-x86_64.tar.xz /usr/local/soft/
1.6.2 然后进行解压,注意这个文件是.xz文件
注意:-Jxvf 中的J为大写的
tar -Jxvf mysql-8.0.30-linux-glibc2.12-x86_64.tar.xz
我这里的文件是.xz文件,如果你下载的文件是**.tar.gz文件的话用 :tar -zxvf +文件命令
给解压后的文件重命名
mv mysql-8.0.30-linux-glibc2.12-x86_64.tar.xz mysql8
1| vim /etc/my.cnf
在my.cnf文件中加入以下配置:
- [mysqld]
- # 设置3306端口
- port=3306
-
- # 设置mysql的安装目录
- basedir=/usr/local/soft/mysql8
-
- # 设置mysql数据库的数据的存放目录
- datadir=/usr/local/soft/mysql8/data
-
- # 允许最大连接数/
- max_connections=10000
-
- # 允许连接失败的次数。这是为了防止有人从该主机试图攻击数据库系统
- max_connect_errors=10
-
- # 服务端使用的字符集默认为UTF8
- #character-set-server=UTF8
-
- # 创建新表时将使用的默认存储引擎
- default-storage-engine=INNODB
-
- # 默认使用“mysql_native_password”插件认证
- default_authentication_plugin=mysql_native_password
-
- [mysql]
- # 设置mysql客户端默认字符集
- default-character-set=utf8
-
- [client]
- # 设置mysql客户端连接服务端时默认使用的端口
- port=3306
- default-character-set=utf8
- user=mysql

在mysql的安装目录下新建文件data
mkdir data
创建用户组并给用户组权限
- [root@ecs-s6-medium-2-linux-20191122095023 mysql]# groupadd mysql
- [root@ecs-s6-medium-2-linux-20191122095023 mysql]# useradd -rg mysql mysql
- [root@ecs-s6-medium-2-linux-20191122095023 mysql]# chown -R mysql:mysql /usr/local/soft/mysql8/
初始化mysql数据库
记住mysql的初始密码
- [mysql@wnode1 mysql8]$ cd support-files/
- [mysql@wnode1 support-files]$ ls
- mysqld_multi.server mysql-log-rotate mysql.server
- [mysql@wnode1 support-files]$ ./mysql.server start
- Starting MySQL SUCCESS!
- [mysql@wnode1 support-files]$
- [root@wnode1 mysql8]#
- [root@wnode1 mysql8]#
- [root@wnode1 mysql8]#
- [root@wnode1 mysql8]# ./bin/mysql -h 127.0.0.1 -u root -p
- Enter password:
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 8
- Server version: 8.0.30 MySQL Community Server - GPL
-
- Copyright (c) 2000, 2022, 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>

将root用户的密码设置为 123456
alter user 'root'@'localhost' identified by '123456';
注意当你mysql安装的路径不是/usr/local/mysql 时启动可能会报错
这时我们需要修改下mysql启动脚本的配置文件
- [root@wnode1 mysql8]#
- [root@wnode1 mysql8]#
- [root@wnode1 mysql8]#
- [root@wnode1 mysql8]# su mysql
- [mysql@wnode1 mysql8]$ cd support-files/
- [mysql@wnode1 support-files]$ vim mysql.server
[mysql@wnode1 support-files]$ vim mysqld_multi.server
用root登录mysql: ./bin/mysql -h 127.0.0.1 -u root -p
切换到mysql数据库: use mysql
更改root的权限,允许其他IP地址登录: update user set host = "%" where user = "root";
查看表数据: select host, user from user;
刷新权限: flush privileges;
- [root@ecs-s6-medium-2-linux-20191122095023 mysql-8.0]#
- [root@ecs-s6-medium-2-linux-20191122095023 mysql-8.0]# pwd
- /usr/local/mysql
- [root@ecs-s6-medium-2-linux-20191122095023 mysql-8.0]# ./bin/mysql -u root -p
- Enter password:
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 9
- Server version: 8.0.18
-
- 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>
- 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>
- mysql> update user set host = '%' where user = 'root';
- Query OK, 1 row affected (0.00 sec)
- Rows matched: 1 Changed: 1 Warnings: 0
- mysql>
- mysql> select host, user from user;
- +-----------+------------------+
- | host | user |
- +-----------+------------------+
- | % | root |
- | localhost | mysql.infoschema |
- | localhost | mysql.session |
- | localhost | mysql.sys |
- +-----------+------------------+
- 4 rows in set (0.00 sec)
- mysql>
- mysql> flush privileges;
- Query OK, 0 rows affected (0.00 sec)
- mysql>
- ————————————————
- 版权声明:本文为CSDN博主「慧梦之旅」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
- 原文链接:https://blog.csdn.net/qq_35330159/article/details/103236316

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。