linux-mysql的安装配置数据库和表的操作
mariadb安装
1.安装mariadb服务
dnf -y install mariadb-server Last metadata expiration check: 0:51:34 ago on Wed 28 Apr 2021 03:06:50 PM CST. Dependencies resolved. =========================================================================================================================================================================================== Package Architecture Version Repository Size =========================================================================================================================================================================================== Installing: mariadb-server x86_64 3:10.3.28-1.module_el8.3.0+757+d382997d appstream 16 M Installing dependencies: mariadb x86_64 3:10.3.28-1.module_el8.3.0+757+d382997d appstream 6.0 M mariadb-common x86_64 3:10.3.28-1.module_el8.3.0+757+d382997d appstream 64 k mariadb-connector-c x86_64 3.1.11-2.el8_3 appstream 200 k mariadb-connector-c-config noarch 3.1.11-2.el8_3 appstream 15 k mariadb-errmsg x86_64 3:10.3.28-1.module_el8.3.0+757+d382997d appstream 234 k perl-DBD-MySQL x86_64 4.046-3.module_el8.1.0+203+e45423dc appstream 后面省略...
2.启动服务
[root@zwy1 ~]# systemctl start mariadb
3.配置和工具的使用
#启动mysql并设置开机自动启动 systemctl enable --now mysqld systemctl status mysqld #确保3306端口已经监听起来
ss -antl
#语法:mysql [OPTIONS] [database]
#常用的OPTIONS:
# -uUSERNAME 指定用户名,默认为root
# -hHOST 指定服务器主机,默认为localhost,推荐使用ip地址
# -pPASSWORD 指定用户的密码
# -P# 指定数据库监听的端口,这里的#需用实际的端口号代替,如-P3307
# -V 查看当前使用的mysql版本
# -e 不登录mysql执行sql语句后退出,常用于脚本
[root@zwy1 ~]# mysql #进入mysql Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 14 Server version: 10.3.28-MariaDB MariaDB Server Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> set password = password('4564949a'); #设置密码 Query OK, 0 rows affected (0.001 sec) MariaDB [(none)]> quit Bye [root@zwy1 ~]# mysql -uroot -p #通过用户密码登录 Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 16 Server version: 10.3.28-MariaDB MariaDB Server Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
[root@zwy1 ~]# mysql -V #远程查看
mysql Ver 15.1 Distrib 10.3.28-MariaDB, for Linux (x86_64) using readline 5.1
[root@zwy1 ~]# mysql -uroot -p4564949a -e 'show databases;'
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
4.创建数据库
MariaDB [(none)]> create database test; Query OK, 1 row affected (0.000 sec) MariaDB [(none)]> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | +--------------------+ 4 rows in set (0.000 sec)
创建表
MariaDB [(none)]> create database test; Query OK, 1 row affected (0.000 sec) MariaDB [(none)]> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | +--------------------+ 4 rows in set (0.000 sec) MariaDB [(none)]> use test Database changed
MariaDB [test]> create table zwy1(id int not null,name varchar(60) null,age tinyint);
Query OK, 0 rows affected (0.004 sec)
输入数据
MariaDB [test]> insert into zwy1 (id,name,age) values(1,'zhangsan',21),(2,'lisi',22),(3,'wangwu',23),(4,'xyq',24),(5,'zwy',24),(6,'cyx',24); Query OK, 6 rows affected (0.001 sec) Records: 6 Duplicates: 0 Warnings: 0 MariaDB [test]> desc zwy1; +-------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+-------------+------+-----+---------+-------+ | id | int(11) | NO | | NULL | | | name | varchar(60) | YES | | NULL | | | age | tinyint(4) | YES | | NULL | | +-------+-------------+------+-----+---------+-------+ 3 rows in set (0.001 sec) MariaDB [test]> select * from zwy1; +----+----------+------+ | id | name | age | +----+----------+------+ | 1 | zhangsan | 21 | | 2 | lisi | 22 | | 3 | wangwu | 23 | | 4 | xyq | 24 | | 5 | zwy | 24 | | 6 | cyx | 24 | +----+----------+------+ 6 rows in set (0.000 sec)

浙公网安备 33010602011771号