暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

MySQL常规安装

原创 那日苏 恩墨学院 2021-12-14
622

操作系统版本:7.5

    链接:https://pan.baidu.com/s/1hFFm53tp-81-QfGYx36Dgw
    提取码:yszv

mysql版本:8.0.25

    下载地址:https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.25-linux-glibc2.12-x86_64.tar.xz


安装前准备

1.1上传并解压安装包

[root@mysql11 Desktop]# pwd
/root/Desktop

[root@mysql11 Desktop]#tar -xvf mysql-8.0.25-linux-glibc2.12-x86_64.tar.xz 

[root@mysql11 Desktop]# ll
total 875216
drwxr-xr-x. 9 root root       129 Dec 14 08:09 mysql-8.0.25-linux-glibc2.12-x86_64
-rwxrw-rw-. 1 root root 896219776 Oct  8 04:13 mysql-8.0.25-linux-glibc2.12-x86_64.tar.xz


1.2将解压的软件迁移至/usr/local/,并改名称mysql

[root@mysql11 local]# mv mysql-8.0.25-linux-glibc2.12-x86_64/  mysql
[root@mysql11 local]# 
[root@mysql11 local]# 
[root@mysql11 local]# ll
total 0
drwxr-xr-x. 2 root root   6 Apr 11  2018 bin
drwxr-xr-x. 2 root root   6 Apr 11  2018 etc
drwxr-xr-x. 2 root root   6 Apr 11  2018 games
drwxr-xr-x. 2 root root   6 Apr 11  2018 include
drwxr-xr-x. 2 root root   6 Apr 11  2018 lib
drwxr-xr-x. 2 root root   6 Apr 11  2018 lib64
drwxr-xr-x. 2 root root   6 Apr 11  2018 libexec
drwxr-xr-x. 9 root root 129 Dec 14 08:09 mysql
drwxr-xr-x. 2 root root   6 Apr 11  2018 sbin
drwxr-xr-x. 5 root root  49 Oct  6 23:19 share
drwxr-xr-x. 2 root root   6 Apr 11  2018 src
[root@mysql11 local]# 


1.3创建mysql用户属组

[root@mysql11 local]# groupadd mysql
[root@mysql11 local]# cat /etc/group|grep mysql
mysql:x:1001:
[root@mysql11 local]# 


1.4创建mysql用户

[root@mysql11 local]# useradd mysql -g mysql
[root@mysql11 local]# 
[root@mysql11 local]# cat /etc/passwd|grep mysql
mysql:x:1001:1001::/home/mysql:/bin/bash


1.5将解压的安装包目录进行属组更改

[root@mysql11 local]# chown -R mysql:mysql mysql
[root@mysql11 local]# 
[root@mysql11 local]# ll
total 0
drwxr-xr-x. 2 root  root    6 Apr 11  2018 bin
drwxr-xr-x. 2 root  root    6 Apr 11  2018 etc
drwxr-xr-x. 2 root  root    6 Apr 11  2018 games
drwxr-xr-x. 2 root  root    6 Apr 11  2018 include
drwxr-xr-x. 2 root  root    6 Apr 11  2018 lib
drwxr-xr-x. 2 root  root    6 Apr 11  2018 lib64
drwxr-xr-x. 2 root  root    6 Apr 11  2018 libexec
drwxr-xr-x. 9 mysql mysql 129 Dec 14 08:09 mysql
drwxr-xr-x. 2 root  root    6 Apr 11  2018 sbin
drwxr-xr-x. 5 root  root   49 Oct  6 23:19 share
drwxr-xr-x. 2 root  root    6 Apr 11  2018 src
[root@mysql11 local]# 



安装阶段

2.1开始使用root用户初始化mysql安装,会在datadir路径生成新的文件

[root@mysql11 mysql]# bin/mysqld --initialize --user=mysql --datadir /usr/local/mysql/datadir
2021-12-14T13:15:28.220995Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.25) initializing of server in progress as process 56765
2021-12-14T13:15:28.234214Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-12-14T13:15:29.011219Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2021-12-14T13:15:29.871430Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: Uzy4Gjj?W#*l
[root@mysql11 mysql]# 

[root@mysql11 mysql]# ls -lrt total 292 -rw-r--r--. 1 mysql mysql 666 Apr 23 2021 README -rw-r--r--. 1 mysql mysql 274942 Apr 23 2021 LICENSE drwxr-xr-x. 4 mysql mysql 30 Apr 23 2021 man drwxr-xr-x. 3 mysql mysql 4096 Apr 23 2021 include drwxr-xr-x. 2 mysql mysql 55 Apr 23 2021 docs drwxr-xr-x. 2 mysql mysql 77 Apr 23 2021 support-files drwxr-xr-x. 28 mysql mysql 4096 Apr 23 2021 share drwxr-xr-x. 6 mysql mysql 201 Apr 23 2021 lib drwxr-xr-x. 2 mysql mysql 4096 Apr 23 2021 bin drwxr-x---. 6 mysql mysql 4096 Dec 14 08:15 datadir [root@mysql11 mysql]#

2.2将mysql服务加入到自动启动

[root@mysql11 mysql]# pwd
/usr/local/mysql
[root@mysql11 mysql]# cp support-files/mysql.server /etc/init.d/mysql.server 
[root@mysql11 mysql]# 
    


##注意启动时报错

[root@mysql11 mysql]# /etc/init.d/mysql.server start 
Starting MySQL.Logging to '/usr/local/mysql/data/mysql11.err'.
 ERROR! The server quit without updating PID file (/usr/local/mysql/data/mysql11.pid).
[root@mysql11 mysql]#

##将datadir改成data目录即可

[root@mysql11 mysql]# mv datadir  data
[root@mysql11 mysql]# 
[root@mysql11 mysql]# ls -lrt 
total 292
-rw-r--r--.  1 mysql mysql    666 Apr 23  2021 README
-rw-r--r--.  1 mysql mysql 274942 Apr 23  2021 LICENSE
drwxr-xr-x.  4 mysql mysql     30 Apr 23  2021 man
drwxr-xr-x.  3 mysql mysql   4096 Apr 23  2021 include
drwxr-xr-x.  2 mysql mysql     55 Apr 23  2021 docs
drwxr-xr-x.  2 mysql mysql     77 Apr 23  2021 support-files
drwxr-xr-x. 28 mysql mysql   4096 Apr 23  2021 share
drwxr-xr-x.  6 mysql mysql    201 Apr 23  2021 lib
drwxr-xr-x.  2 mysql mysql   4096 Apr 23  2021 bin
drwxr-x---.  6 mysql mysql   4096 Dec 14 08:15 data
[root@mysql11 mysql]# 

[root@mysql11 mysql]# /etc/init.d/mysql.server start Starting MySQL.Logging to '/usr/local/mysql/data/mysql11.err'. SUCCESS! [root@mysql11 mysql]#

2.3启动mysql,查看端口是否打开

[root@mysql11 mysql]# netstat -an|grep LISTE|grep 3306
tcp6       0      0 :::33060                :::*                    LISTEN     
tcp6       0      0 :::3306                 :::*                    LISTEN     
[root@mysql11 mysql]# 


2.4修改临时密码

登陆前修改root用户的环境变量,并生效变量
[root@mysql11 bin]# cat ~/.bash_profile 
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin:/usr/local/mysql/bin

export PATH
[root@mysql11 bin]#  source ~/.bash_profile 

[root@mysql11 bin]# 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.25

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> 
mysql> 
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> 
mysql> alter user user() identified by 'mysql'; Query OK, 0 rows affected (0.00 sec) mysql> exit Bye [root@mysql11 bin]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 9 Server version: 8.0.25 MySQL Community Server - GPL 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; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.01 sec)



2.5修改密码8.0之前的不同方式

--8.0之前支持的修改密码方式
set password=password('mysql');

--8.0之后修改密码方式
alter user user() identified by 'mysql';










「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

文章被以下合辑收录

评论