MySql数据库Linux

MySQL:Ubuntu下安装MySQL 8.0记录

2021-06-01  本文已影响0人  xiaogp

摘要:MySQLUbuntu

为了体验一下高版本MySQL对于JSON多值索引的支持功能,特地在Ubuntu下下载一个MySQL 8.0.25测试一下

(1)安装包下载

Ubuntu下默认aptget install安装的MySQL是5.7.30版本的,下载最新的MySQL一种方式是去官网下载安装包,然后本机离线安装,官网地址
https://dev.mysql.com/downloads/mysql/
查看linux位数64位,选择对应的安装包下载

root@ubuntu:~# getconf LONG_BIT
64

(2)本地解压

解压并将所有文件移动到/usr/local/mysql

root@ubuntu:~# tar -zxvf mysql-8.0.25-linux-glibc2.12-x86_64.tar.xz
root@ubuntu:~# mkdir -p /usr/local/mysql
root@ubuntu:~# mv mysql-8.0.25-linux-glibc2.12-x86_64/* /usr/local/mysql

(3)创建MySQL配置文件

添加MySQL配置文件,如果配置文件中指定的路径不存在需要提前创建

root@ubuntu:~# vim /etc/my.cnf 
[client]
port=3306
socket=/tmp/mysql/mysql.sock

[mysqld]
port=3306
user=mysql
socket=/tmp/mysql/mysql.sock
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
log-error=/usr/local/mysql/data/error.log
pid-file = /usr/local/mysql/data/mysql.pid
tmpdir = /tmp

(4)MySQL初始化

创建用户组

root@ubuntu:~# groupadd mysql
root@ubuntu:~# useradd -r -g mysql mysql
root@ubuntu:~# chown -R mysql:mysql /tmp/mysql

MySQL初始化,此处保证data目录下为空,如果data下已经存在文件,可以清空data目录

root@ubuntu:~# cd /usr/local/mysql/bin
root@ubuntu:~# ./mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/

(5)启动MySQL服务

启动MySQL服务,查看是否报错,如果报错去/usr/local/mysql/data/error.log查看错误日志

root@ubuntu:~# cd /usr/local/mysql/support-files
root@ubuntu:~# ./mysql.server start
Starting MySQL
.. * 

登录MySQL客户端,在error.log中生成了初始密码root@localhost: rJP4Z-PyrkNk,查看文件

2021-05-31T12:11:51.884056Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: rJP4Z-PyrkNk
root@ubuntu:~# cd /usr/local/mysql/bin
root@ubuntu:~# ./mysql -uroot -prJP4Z-PyrkNk
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.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> select @@version;
+-----------+
| @@version |
+-----------+
| 8.0.25    |
+-----------+
1 row in set (0.00 sec)

(6)修改初始密码

修改初始密码为123456

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.09 sec)

(6)添加环境变量

添加MySQL到环境变量,添加一行

root@ubuntu:~# vim ~/.bashrc
export PATH=$PATH:/usr/local/mysql/bin
root@ubuntu:~# source ~/.bashrc
上一篇下一篇

猜你喜欢

热点阅读