下载
[root@test downloads]# wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.28-linux-glibc2.12-x86_64.tar.xz
--2023-03-24 10:22:56-- https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.28-linux-glibc2.12-x86_64.tar.xz
Resolving dev.mysql.com (dev.mysql.com)... 23.198.140.150, 2600:1417:1000:884::2e31, 2600:1417:1000:8ac::2e31
Connecting to dev.mysql.com (dev.mysql.com)|23.198.140.150|:443... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: https://cdn.mysql.com//archives/mysql-8.0/mysql-8.0.28-linux-glibc2.12-x86_64.tar.xz [following]
--2023-03-24 10:22:56-- https://cdn.mysql.com//archives/mysql-8.0/mysql-8.0.28-linux-glibc2.12-x86_64.tar.xz
Resolving cdn.mysql.com (cdn.mysql.com)... 104.75.165.42
Connecting to cdn.mysql.com (cdn.mysql.com)|104.75.165.42|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1204277208 (1.1G) [text/plain]
Saving to: ‘mysql-8.0.28-linux-glibc2.12-x86_64.tar.xz’
100%[==================================================================================================================================================================================================================================>] 1,204,277,208 11.6MB/s in 94s
2023-03-24 10:24:30 (12.3 MB/s) - ‘mysql-8.0.28-linux-glibc2.12-x86_64.tar.xz’ saved [1204277208/1204277208]
[root@test downloads]# ll
total 1176056
-rw-r--r-- 1 root root 1204277208 Dec 18 2021 mysql-8.0.28-linux-glibc2.12-x86_64.tar.xz
解压并移到安装目录
[root@test downloads]# tar -xf mysql-8.0.28-linux-glibc2.12-x86_64.tar.xz
[root@test downloads]# mv ./mysql-8.0.28-linux-glibc2.12-x86_64 /usr/local
[root@test downloads]# cd /usr/local
[root@test local]# mv mysql-8.0.28-linux-glibc2.12-x86_64 mysql
[root@test local]# cd /usr/local/mysql
修改mysql配置文件
新机器会自带 /etc/my.cnf
配置文件
[root@test mysql]# cat /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
因该是装机自带的mariadb的配置
[root@test mysql]# yum info mariadb
Loaded plugins: fastestmirror, langpacks, releasever-adapter, update-motd
Loading mirror speeds from cached hostfile
Available Packages
Name : mariadb
Arch : x86_64
Epoch : 1
Version : 5.5.68
Release : 1.1.al7
Size : 8.9 M
Repo : updates/2.1903/x86_64
Summary : A community developed branch of MySQL
URL : http://mariadb.org
License : GPLv2 with exceptions and LGPLv2 and BSD
Description : MariaDB is a community developed branch of MySQL.
: MariaDB is a multi-user, multi-threaded SQL database server.
: It is a client/server implementation consisting of a server daemon (mysqld)
: and many different client programs and libraries. The base package
: contains the standard MariaDB/MySQL client programs and generic MySQL files.
可以不用管,重写里面的内容给mysql8用就行了
写入如下内容:
[client]
#password = your_password
port = 3306
socket = /tmp/mysql.sock
[mysqld]
port = 3306
socket = /tmp/mysql.sock
datadir = /usr/local/mysql/var
character-set-server=utf8mb4
skip-external-locking
key_buffer_size = 3072M
max_allowed_packet = 32M
table_open_cache = 512
sort_buffer_size = 32M
net_buffer_length = 8K
read_buffer_size = 16M
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 32M
thread_cache_size = 64
#query_cache_size = 256M
tmp_table_size = 128M
## performance_schema_max_table_instances = 4000
explicit_defaults_for_timestamp = true
#skip-networking
max_connections = 3000
max_connect_errors = 100
open_files_limit = 102400
#skip-grant-tables
skip_ssl
log-bin=mysql-bin
binlog_format=mixed
server-id = 1
expire_logs_days = 3
early-plugin-load = ""
default_storage_engine = InnoDB
innodb_file_per_table = 1
innodb_data_home_dir = /usr/local/mysql/var
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = /usr/local/mysql/var
innodb_buffer_pool_size = 1G
innodb_log_file_size = 128M
innodb_log_buffer_size = 64M
innodb_flush_log_at_trx_commit = 2
innodb_lock_wait_timeout = 50
#sql_mode=NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
#sql_mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
sql_mode=ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
[mysqldump]
quick
max_allowed_packet = 32M
[mysql]
auto-rehash
[myisamchk]
key_buffer_size = 128M
sort_buffer_size = 2M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
#[mysqld_safe]
#malloc-lib=/usr/lib/libtcmalloc.so
添加mysql用户useradd -s /sbin/nologin mysql
,并修目录用户权限chown -R mysql:mysql /usr/local/mysql
初始化mysql
此步骤会有默认密码。需要记住,下一步修改密码时会用到
[root@test mysql]# ./bin/mysqld --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/var --initialize
2023-03-24T02:45:44.150570Z 0 [Warning] [MY-011068] [Server] The syntax '--ssl=off' is deprecated and will be removed in a future release. Please use --tls-version=invalid instead.
2023-03-24T02:45:44.150585Z 0 [Warning] [MY-011068] [Server] The syntax 'expire-logs-days' is deprecated and will be removed in a future release. Please use binlog_expire_logs_seconds instead.
2023-03-24T02:45:44.150619Z 0 [Warning] [MY-010915] [Server] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2023-03-24T02:45:44.150679Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.28) initializing of server in progress as process 7114
2023-03-24T02:45:44.300258Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2023-03-24T02:45:46.295337Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2023-03-24T02:45:47.210554Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: C2lf:%EqtdfW
mysql启动文件拷贝一份到 /etc/init.d
目录
Linux cp 命令:
cp [options] source dest
orcp [options] source... directory
参数说明:
-a:此选项通常在复制目录时使用,它保留链接、文件属性,并复制目录下的所有内容。其作用等于dpR参数组合。
-d:复制时保留链接。这里所说的链接相当于 Windows 系统中的快捷方式。
-f:覆盖已经存在的目标文件而不给出提示。
-i:与 -f 选项相反,在覆盖目标文件之前给出提示,要求用户确认是否覆盖,回答 y 时目标文件将被覆盖。
-p:除复制文件的内容外,还把修改时间和访问权限也复制到新文件中。
-r:若给出的源文件是一个目录文件,此时将复制该目录下所有的子目录和文件。
-l:不复制文件,只是生成链接文件
[root@test mysql]# cp -a ./support-files/mysql.server /etc/init.d/mysql
[root@test mysql]# chmod +x /etc/init.d/mysql
[root@test mysql]# /etc/init.d/mysql start
Starting MySQL.Logging to '/usr/local/mysql/var/test.err'.
. [ OK ]
[root@test mysql]# ln -s /usr/local/mysql/bin/mysql /usr/bin/
用临时密码登入mysql修改root的新密码
[root@test mysql]# mysql -uroot -pC2lf:%EqtdfW
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 9
Server version: 8.0.28
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> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '你的新密码';
Query OK, 0 rows affected (0.01 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
测试重登
[root@test mysql]# mysql -uroot -p你的新密码
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 10
Server version: 8.0.28 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> exit
Bye
tips: 使用命令查看my.cnf文件路径,按以下输出内容,优先使用
/etc/my.cnf
,不存在则往后依次查找
[root@test mysql]# mysql --verbose --help|grep -A 1 'Default options'
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf
网友评论