赞
踩
mysql安装可以有三种方式:1.今天做的是二进制安装 2.yum仓库安装,这个要联网用yum原装 3.source code安装(源码编译安装)
打开官网。点击download
拉到底部点击社区服务下载
点击后,默认跳转最新版本mysql下载
点击archives档案库,选择以前的版本
三个选项分别是:选择mysql版本、选择安装方法(这里选择预编译,源码安装也在这里选)、选择操作系统以及系统glibc版本
操作系统glibc查看方法
[root@hisdg data]# rpm -q glibc
glibc-2.17-196.el7.x86_64
点击download下载,不知道为什么这里8.0.27只有minimal
下载完成后我们得到一个安装包
mysql-8.0.27-linux-glibc2.17-x86_64-minimal.tar.xz
把这个安装包放到服务器上,最好放在/usr/local/或者/var/local/,一般安装在这两个目录。
[root@hisdg local]# tar -xvf mysql-8.0.27-linux-glibc2.17-x86_64-minimal.tar.xz
[root@hisdg local]# ls
bin etc games include lib lib64 libexec mysql-8.0.27-linux-glibc2.17-x86_64-minimal mysql-8.0.27-linux-glibc2.17-x86_64-minimal.tar.xz sbin share src
--解压后得到一个mysql-8.0.27-linux-glibc2.17-x86_64-minimal文件夹
[root@hisdg local]# mv mysql-8.0.27-linux-glibc2.17-x86_64-minimal mysql-8.0.27
--文件夹名字太长,换个名字
[root@hisdg local]# ls
bin etc games include lib lib64 libexec mysql-8.0.27 mysql-8.0.27-linux-glibc2.17-x86_64-minimal.tar.xz sbin share src
[root@hisdg lib]# cd /usr/local
[root@hisdg local]# ls
bin etc games include lib lib64 libexec mysql-8.0.27 mysql-8.0.27-linux-glibc2.17-x86_64-minimal.tar.xz sbin share src
[root@hisdg local]# cd mysql-8.0.27/
[root@hisdg mysql-8.0.27]# ls
bin docs include lib LICENSE man README share support-files
[root@hisdg mysql-8.0.27]# mkdir data
[root@hisdg mysql-8.0.27]# mkdir log
[root@hisdg local]# cat /etc/my.cnf
[mysqld]
basedir=/usr/local/mysql-8.0.27
datadir=/usr/local/mysql-8.0.27/data
--主要是修改basedir和datadir
#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
[root@hisdg mysql-8.0.27]# ./bin/mysqld --initialize --user=root --basedir=/usr/local/mysql-8.0.27 --datadir=/usr/local/mysql-8.0.27/data
2022-03-07T02:51:34.351443Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2022-03-07T02:51:34.351537Z 0 [System] [MY-013169] [Server] /usr/local/mysql-8.0.27/bin/mysqld (mysqld 8.0.27) initializing of server in progress as process 8738
2022-03-07T02:51:34.361878Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-03-07T02:51:36.820255Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-03-07T02:51:40.381255Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1 is enabled for channel mysql_main
2022-03-07T02:51:40.381276Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1.1 is enabled for channel mysql_main
2022-03-07T02:51:40.438048Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: **%Sb&!Ox;A6ok**
--结尾这玩意儿是mysql的root用户的临时密码,要记录一下,首次登录需要用到这个随机密码,首次登录后,会提示你将临时密码修改掉。
5.1 修改mysql启动脚本
[root@hisdg local]# cd /usr/local/mysql-8.0.27/support-files/
[root@hisdg support-files]# pwd
/usr/local/mysql-8.0.27/support-files
[root@hisdg support-files]# cat mysql.server
--修改如下两行
basedir=/usr/local/mysql-8.0.27
datadir=/usr/local/mysql-8.0.27/data
5.2复制mysql.server到启动目录并赋权
[root@hisdg support-files]# cp mysql.server /etc/rc.d/init.d/mysqld
[root@hisdg support-files]# chmod +x /etc/rc.d/init.d/mysqld
5.3修改环境变量
vi /etc/profile
--文件末尾追加
MYSQL_HOME=/usr/local/mysql-8.0.27
export PATH=$PATH:$MYSQL_HOME/bin
source /etc/profile --生效环境变量
--不加环境变量会报错
[root@hisdg support-files]# mysql -uroot -p
bash: mysql: command not found...
[root@hisdg support-files]# service mysqld start
Starting MySQL.2022-03-07T02:54:55.853233Z mysqld_safe error: log-error set to '/var/log/mariadb/mariadb.log', however file don't exists. Create writable for user 'mysql'.
ERROR! The server quit without updating PID file (/var/lib/mysql/hisdg.pid).
--这个报错我把/etc/my.conf里的socket注释掉就好了,也不知道是不是这个原因
正常启动
[root@hisdg data]# service mysqld restart
ERROR! MySQL server PID file could not be found!
Starting MySQL.Logging to '/usr/local/mysql-8.0.27/data/hisdg.err'.
... SUCCESS!
[root@hisdg ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.27
Copyright (c) 2000, 2021, 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> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql>
--第一次用临时密码登录提示需要修改密码
首次登陆需要修改密码
mysql>alter user root@'localhost' identified by '复杂密码';
mysql>\q #退出
或者
[root@node1 ~]#mysqladmin -uroot -p'&Sl>/PH3p.wj' password 'Huawei12#$'
或者
mysql> select user,host,authentication_string from mysql.user;
+---------------+-----------+-------------------------------------------+
| user | host | authentication_string |
+---------------+-----------+-------------------------------------------+
| root | localhost | *6FC9584BD608910F59D5B0561CE6CBFEFDCCEA3A |
| mysql.session | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| mysql.sys | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
+---------------+-----------+-------------------------------------------+
mysql> update mysql.user set authentication_string=password('HPdl380g9#$') where user='root' and host='localhost';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
mysql> flush privileges; #刷新授权表
Query OK, 0 rows affected (0.00 sec)
mysql> \q
Bye
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。