Linux安装mysql8.0.18

本文提供在Linux64位系统上安装MySQL8.0的详细步骤,包括下载、解压、移动、创建目录、用户组、权限设置、初始化数据库、配置环境变量、服务配置及启动等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、Linux64位mysql下载

# wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz

2、解压安装包

# tar -xvf mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz 

解压后的结果

# ls
mysql-8.0.18-linux-glibc2.12-x86_64  mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz

3、将安装包移动到/usr/local/目录下,并重命名mysql

# mv mysql-8.0.18-linux-glibc2.12-x86_64 /usr/local/mysql

4、在mysql目录下创建data目录,存放数据

# cd /usr/local/mysql
# mkdir data

创建mysql用户组合mysql用户

# groupadd mysql
# useradd -g mysql mysql

5、改变mysql目录权限

# chown -R  mysql.mysql /usr/local/mysql

6、初始化数据库

# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
2020-01-03T03:18:55.148944Z 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.
2020-01-03T03:18:55.148978Z 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.
2020-01-03T03:18:55.149090Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.18) initializing of server in progress as process 15588
2020-01-03T03:19:00.601144Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: qj7Vc+-hyha/

7、配置mysql
在mysql/support-files创建文件my-default.cnf

[root@my ~]# cd /usr/local/mysql/support-files/
[root@my support-files]# touch my-default.cnf

复制配置文件到/etc/my.cnf

[root@iZ2ze6xk support-files]# cp -a ./my-default.cnf  /etc/my.cnf

编辑 my.cnf

[root@localhost bin]#  vi /etc/my.cnf

[mysqld]
datadir=/usr/local/mysql/data
port = 3306
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
symbolic-links=0
max_connections=400
innodb_file_per_table=1
#表名大小写不明感,敏感为
lower_case_table_names=1

8、配置mysql服务

[root@iZ2ze6Z etc]# cd /usr/local/mysql/
[root@iZ2ze6xk mysql]# cp -a ./support-files/mysql.server  /etc/init.d/mysqld
[root@iZ2ze6x mysql]# chmod -x /etc/rc.d/init.d/mysqld 
[root@iZ2ze6xk mysql]# chkconfig --add mysqld
#### 检查是否生效
[root@iZ2ze6xkq mysql]# chkconfig --list mysqld

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off

9、配置环境变量

 
编辑 / etc/profile 文件
 
[root@my ~]# vi /etc/profile
 
在 profile 文件底部添加如下两行配置,保存后退出
 
PATH=/data/mysql/bin:/data/mysql/lib:$PATH
 
export PATH
 
设置环境变量立即生效
 
[root@my ~]source /etc/profile

10、启动mysql服务器

[root@localhost /]# /usr/local/mysql/support-files/mysql.server start

显示如下说明服务器安装成功:

Starting MySQL.Logging to '/usr/local/mysql/data/iZ2ze6xkq7xjxmfnsdw27yZ.err'.
..                                                         [  OK  ]

11、登录mysql,修改密码(密码为步骤6生成的临时密码,初始化数据库时的临时密码)

[root@localhost /]#  mysql -u root -p
Enter password:
mysql> set password for root@localhost = 'yourpassword'

12、开放远程连接

mysql>use mysql;
msyql>update user set user.Host='%' where user.User='root';
mysql>flush privileges;

示例:

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> update user set user.Host='%' where user.User='root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

13、设置开机自动启动

1、将服务文件拷贝到init.d下,并重命名为mysql
[root@localhost /]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
2、赋予可执行权限
[root@localhost /]# chmod +x /etc/init.d/mysqld
3、添加服务
[root@localhost /]# chkconfig --add mysqld
4、显示服务列表
[root@localhost /]# chkconfig --list
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值