linux安装MySql8.0

安装MySql

mysql-cluster-8.0.24-linux-glibc2.12-x86_64.tar.gz
1,将mysql文件放在/usr/local/
2,解压
[root@localhost local]# tar -xvf mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz 
3,将解压后的文件改名为mysql
[root@localhost local]# mv mysql-8.0.18-linux-glibc2.12-x86_64 mysql
4,在mysql文件加下创建data
[root@localhost mysql]# mkdir data
5,进入/usr/local目录下,创建用户和用户组并授权
[root@Mysql-server local]# pwd
/usr/local
[root@Mysql-server local]# groupadd mysql
[root@Mysql-server local]# useradd -r -g mysql mysql
[root@Mysql-server local]# chown -R mysql:mysql
6,安装libaio,
[root@localhost mysql]# rpm -qa|grep libaio
[root@localhost mysql]# yum -y install libaio-devel.x86_64
7,初始化数据库
[root@Mysql-server mysql]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
8,初始话完成之后会随机生成密码
2021-06-09T03:24:40.794365Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: rrDNP4=g;H>g
9,修改/usr/local/mysql当前目录的用户
[root@Mysql-server mysql]# chown -R root:root ./
[root@Mysql-server mysql]# chown -R mysql:mysql data
10,创建my.cnf
[root@Mysql-server mysql]# cd support-files/
[root@Mysql-server support-files]# touch my-default.cnf
[root@Mysql-server support-files]# chmod 777 ./my-default.cnf
[root@Mysql-server support-files]# ll
总用量 20
-rwxrwxrwx. 1 root root     0 69 11:38 my-default.cnf
-rwxr-xr-x. 1 root root  1061 326 12:24 mysqld_multi.server
-rw-r--r--. 1 root root  2027 326 13:07 mysql-log-rotate
-rwxr-xr-x. 1 root root 10576 326 13:07 mysql.server
[root@Mysql-server support-files]# cp support-files/my-default.cnf /etc/my.cnf
cp: 无法获取"support-files/my-default.cnf" 的文件状态(stat): 没有那个文件或目录
[root@Mysql-server support-files]# cp my-default.cnf /etc/my.cnf
cp:是否覆盖"/etc/my.cnf"yes

11,配置my.cnf
[root@Mysql-server support-files]# vim /etc/my.cnf
[client]
port = 3306
socket = /tmp/mysql.sock

[mysqld]
init-connect='SET NAMES utf8'
basedir=/usr/local/mysql        # 根据自己的安装目录填写
datadir=/usr/local/mysql/data   # 根据自己的mysql数据目录填写
socket=/tmp/mysql.sock			
max_connections=200				# 允许最大的连接数
character-set-server=utf8		# 服务器使用的字符集默认为8比特编码的latin1字符集
default-storage-engine=INNODB	# 创建新表时将使用的默认储存引擎
12,开机自启,进入/usr/local/mysql/support-files进行设置
[root@Mysql-server support-files]# cp mysql.server /etc/init.d/mysql
[root@Mysql-server support-files]# chmod +x /etc/init.d/mysql

13,注册服务
[root@Mysql-server support-files]# chkconfig --add mysql
[root@Mysql-server support-files]# chkconfig --list mysql
注:该输出结果只显示 SysV 服务,并不包含
原生 systemd 服务。SysV 配置数据
可能被原生 systemd 配置覆盖。

      要列出 systemd 服务,请执行 'systemctl list-unit-files'。
      查看在具体 target 启用的服务请执行
      'systemctl list-dependencies [target]'。

mysql           0:关    1:关    2:开    3:开    4:开    5:开    6:关
14,etc/ld.so.conf要配置路径,不然报错
[root@Mysql-server support-files]# vim /etc/ld.so.conf

文件添加内容
/usr/local/mysql/lib
15,配置环境变量
[root@Mysql-server support-files]# vim /etc/profile

文件最后添加内容
#MYSQL ENVIRONMENT
export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib
16,更新环境变量
[root@Mysql-server support-files]# source /etc/profile
17,启动MySQL服务
[root@Mysql-server ~]# service mysql start
Starting MySQL SUCCESS!
18,登录mysql
[root@Mysql-server ~]# mysql -u root -p
Enter password:
19,修改密码
mysql> alter user 'root'@'localhost' identified by 'sin-8023';
Query OK, 0 rows affected (0.02 sec)
20,开启远程访问
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> select host, user, authentication_string, plugin from user; #查看用户信息
4 rows in set (0.00 sec)


mysql> CREATE USER 'root'@'%' IDENTIFIED BY 'root';     #创建任意ip链接root用户
Query OK, 0 rows affected (3.51 sec)

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION; #授权root用户可以远程登录
Query OK, 0 rows affected (0.24 sec)

mysql> flush privileges;   #立即生效
Query OK, 0 rows affected (0.34 sec)
21,重启服务器
[root@Mysql-server ~]# service mysql restart
Shutting down MySQL..... SUCCESS!
Starting MySQL.......... SUCCESS!
22,防火墙开放3306端口
[root@Mysql-server ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent # 开放3306端口
success
[root@Mysql-server ~]# systemctl restart firewalld   # 重启防火前
[root@Mysql-server ~]# firewall-cmd --list-ports     # 查看是否放行成功
3306/tcp

你可能感兴趣的:(服务器,mysql,linux,centos,数据库,java)