linux安装mysql8.0.18_Linux安装MySQL8.0

Linux安装MySQL8.0

rpm -qa|grep mysql

rpm -qa|grep mariadb

mariadb-libs-5.5.60-1.el7_5.x86_64

rpm -e --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64  执行查询到的rpm包卸载

8.0解压安装步骤

tar xvf mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz

rm -rf mysql-8.0.20-linux-glibc2.12-x86_64.tar.

xz -d mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz

[root@localhost ~]# tar -xvf mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz

[root@localhost ~]# mv mysql-8.0.20-linux-glibc2.12-x86_64 /usr/local/mysql

[root@localhost ~]# cd /usr/local/mysql/

[root@localhost mysql]# mkdir /var/lib/mysql

[root@localhost mysql]# mkdir /usr/local/mysql/data

[root@localhost mysql]# groupadd mysql

[root@localhost mysql]# id mysql  添加用户和组如果之前存在就删除它重新添加

id: mysql: no such user   userdel mysql groupdel mysql

[root@localhost mysql]# useradd -r -g mysql -s /bin/false mysql  一个不可登录的 安全的组

[root@localhost mysql]# chown -R mysql:mysql /var/lib/mysql

[root@localhost mysql]# chown -R mysql:mysql /usr/local/mysql/data

[root@localhost mysql]# chown -R mysql:mysql /usr/local/mysql

[root@localhost mysql]# ls -lsa

修改环境变量

root@localhost mysql]# cd bin/

[root@localhost bin]# pwd

/usr/local/mysql/bin

[root@localhost bin]# vi ~/.bash_profile

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

linux安装mysql8.0.18_Linux安装MySQL8.0_第1张图片

执行exit 退出后 再次连接登录

[root@localhost ~]# which mysql

/usr/local/mysql/bin/mysql  代表mysql安装成功

[root@localhost ~]# mkdir /usr/local/mysql/log  创建日志目录

[root@localhost ~]# chown -R mysql:mysql /usr/local/mysql/log

先创建日志目录并赋予权限

# vi /etc/my.cnf

[mysql]

default-character-set=utf8mb4

socket=/var/lib/mysql/mysql.sock

[mysqld]

port=3306

socket=/var/lib/mysql/mysql.sock

basedir=/usr/local/mysql

character-set-server=utf8mb4

default-storage-engine=INNODB

innodb_buffer_pool_size=200M

max_allowed_packet=16M

explicit_defaults_for_timestamp=1

log-output=FILE

general_log=0

general_log_file=/usr/local/mysql/log/sky02-general.err

slow_query_log=ON

slow_query_log_file=/usr/local/mysql/log/sky02-query.err

long_query_time=10

log-error=/usr/local/mysql/log/sky02-error.err

default-authentication-plugin=mysql_native_password

yum install libaio  需先安装 初始化需依赖它 error while loading shared libraries: libaio.so.1:

/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/

# cd /usr/local/mysql/log/

[root@localhost log]# ls 错误日志查询

[root@itsky ~]# cd /usr/local/mysql/log/

[root@itsky log]# ls

sky02-error.err  sky02-query.err

[root@itsky log]# tail -100f sky02-error.err   查看日志后100行内容 有初始的密码存在

l 创建Linux启动脚本

[root@itsky ~]# vi /usr/lib/systemd/system/mysqld.service

[Unit]

Description=MySQL Server

Documentation=man:mysqld(8)

Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html

After=network.target

After=syslog.target

[Install]

WantedBy=multi-user.target

[Service]

User=mysql

Group=mysql

ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf

LimitNOFILE= 65536

LimitNPROC=65536

系统启动脚本  D服务类型和描述文档A脚本是在网络和系统日志之后启动L文件描述符 文件进程数

赋予权限

chmod u+x /usr/lib/systemd/system/mysqld.service

启动mysql

# systemctl daemon-reload

systemctl status mysqld

systemctl start mysqld

systemctl status mysqld

systemctl stop mysqld

systemctl status mysqld

systemctl enable mysqld 开机自动启动

手动启动和开机启动MySQL

nohup /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf & 敲2次回车

# mysqladmin -uroot -p shutdown -S /var/lib/mysql/mysql.sock 手动停止MySQL

Enter password:

045817479c7b0b3e91fe9b6a3739decd.png

[root@itsky ~]# ps -ef|grep mysql

linux安装mysql8.0.18_Linux安装MySQL8.0_第2张图片

修改密码

mysql> alter user 'root'@'localhost' identified with mysql_native_password by'rootroot';

Query OK, 0 rows affected (0.00 sec)

exit

创建root远程登录

use mysql;

create user 'root'@'%' identified with mysql_native_password by 'root';

mysql> grant all privileges on *.* to 'root'@'%' with grant option;

select host,user from user where user='root';

linux安装mysql8.0.18_Linux安装MySQL8.0_第3张图片

远程登录

firewall-cmd --state  远程连接需关闭防火墙

systemctl stop firewalld.service

systemctl status firewalld.service

# systemctl disable firewalld.service

# mysql -u root -p -h192.168.101.22

创建数据库

mysql> create database itskydb default charset utf8mb4; 创建数据库

Query OK, 1 row affected (0.04 sec)

mysql> create user 'itsky'@'%' identified by 'itsky'; 创建itsky用户

Query OK, 0 rows affected (0.01 sec)

mysql> select host,user from mysql.user; 查看所有用户

mysql> grant all privileges on itsky.* to 'itsky'@'%' with grant option; 用户授权

Query OK, 0 rows affected (0.03 sec)

创建表

use itskydb

mysql>  create table itsky01(

-> id int auto_increment primary key,

-> name varchar(15)

-> ) engine = InnoDB;

Query OK, 0 rows affected (0.04 sec)

数据插入

insert into itsky01 values (1,'xxxx01');

insert into itsky01 values (2,'xxxx02');

insert into itsky01 values (3,'itsky03');

select *from itsky01;

mysql 卸载

删除  /usr/local/mysql /etc/my.cnf /var/lib/mysql  关机 还原

你可能感兴趣的:(linux安装mysql8.0.18_Linux安装MySQL8.0)