linux配置mysql mysql包名:mysql-8.0.22-1.el7.x86_64.rpm-bundle.tar
卸载mariadb
mariadb是mysql的一个分支,安装mysql前先卸载mariadb
1 2 3 [root@localhost mysql]# rpm -qa | grep mariadb mariadb-libs-5.5.68-1.el7.x86_64 [root@localhost mysql]# rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64
在/lib处解压mysql安装文件
1 2 3 4 5 6 7 8 9 10 11 12 13 [root@localhost ~]# mkdir /lib/mysql [root@localhost ~]# mv mysql-8.0.22-1.el7.x86_64.rpm-bundle.tar /lib/mysql [root@localhost ~]# cd /lib/mysql/ [root@localhost mysql]# tar -xvf mysql-8.0.22-1.el7.x86_64.rpm-bundle.tar mysql-community-client-8.0.22-1.el7.x86_64.rpm mysql-community-client-plugins-8.0.22-1.el7.x86_64.rpm mysql-community-common-8.0.22-1.el7.x86_64.rpm mysql-community-devel-8.0.22-1.el7.x86_64.rpm mysql-community-embedded-compat-8.0.22-1.el7.x86_64.rpm mysql-community-libs-8.0.22-1.el7.x86_64.rpm mysql-community-libs-compat-8.0.22-1.el7.x86_64.rpm mysql-community-server-8.0.22-1.el7.x86_64.rpm mysql-community-test-8.0.22-1.el7.x86_64.rpm
安装mysql
注意rpm包依赖
1 2 3 4 5 6 7 [root@localhost mysql]# yum install net-tools [root@localhost mysql]# rpm -ivh mysql-community-common-8.0.22-1.el7.x86_64.rpm [root@localhost mysql]# rpm -ivh mysql-community-client-plugins-8.0.22-1.el7.x86_64.rpm [root@localhost mysql]# rpm -ivh mysql-community-libs-8.0.22-1.el7.x86_64.rpm [root@localhost mysql]# rpm -ivh mysql-community-libs-compat-8.0.22-1.el7.x86_64.rpm [root@localhost mysql]# rpm -ivh mysql-community-client-8.0.22-1.el7.x86_64.rpm [root@localhost mysql]# rpm -ivh mysql-community-server-8.0.22-1.el7.x86_64.rpm
查看配置文件
1 [root@localhost mysql]# vi /etc/my.cnf
第一次登陆
此处的密码为q6QI/wJisam/,建议复制
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 [root@localhost mysql]# systemctl start mysqld [root@localhost mysql]# systemctl enable mysqld [root@localhost mysql]# vi /var/log/mysqld.log 2021-01-03T15:18:20.141644Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.22) initializing of server in progress as process 4891 2021-01-03T15:18:20.162798Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started. 2021-01-03T15:18:21.109059Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended. 2021-01-03T15:18:22.156426Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: q6QI/wJisam/ 2021-01-03T15:18:24.677535Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.22) starting as process 4936 2021-01-03T15:18:24.702687Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started. 2021-01-03T15:18:25.223499Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended. 2021-01-03T15:18:25.420077Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock 2021-01-03T15:18:25.666171Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed. 2021-01-03T15:18:25.666392Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel. 2021-01-03T15:18:25.691072Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.22' socket: '/var/lib/mysql/mysql.sock' port: 3306 MySQL Community Server - GPL. ~ ~ ~ "/var/log/mysqld.log" 11L, 1385C [root@localhost mysql]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g.
修改密码
1 2 mysql> alter user "root"@"localhost" identified by "HelloWorld@mednight4"; Query OK, 0 rows affected (0.00 sec)
创建用户ls
%表示允许远程登陆
1 2 mysql> create user "ls"@"%" identified by "HelloWorld@mednight4"; Query OK, 0 rows affected (0.01 sec)
授权
所有权限
1 2 mysql> grant all on *.* to "ls"@"%" with grant option; Query OK, 0 rows affected (0.00 sec)
刷新
1 2 mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
查找
1 2 3 4 5 6 7 8 9 10 11 mysql> select user,host from mysql.user; +------------------+-----------+ | user | host | +------------------+-----------+ | ls | % | | mysql.infoschema | localhost | | mysql.session | localhost | | mysql.sys | localhost | | root | localhost | +------------------+-----------+ 5 rows in set (0.00 sec)
切换数据库
1 2 3 4 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
修改root用户的远程访问权限
1 2 3 4 mysql> update user set host="%" where user="root"; Query OK, 1 row affected (0.01 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> quit
开启远程端口
1 2 [root@localhost mysql]# firewall-cmd --add-port=3306/tcp success
远程登陆
以HeidiSQL为例
建表
建立数据库hello,建表helloworld
使用pc的powershell查询
改
增
删