标签:into 数据库软件 开源 mysql服务器 配置 要求 软件 ike user
搭建数据库mysql服务器,192.168.4.50
//集体装包rpm -Uvh 包名(支持通配符)
主流的数据库软件:MYSQL ORACLA BDA SQL 。。
MYSQL已经被甲骨文公司收购是开源的(但不是完全免费的) ,其他几个都是闭源的
MYSQL可跨平台
数据库相同版本是装不上的,需要先卸载,否则会有冲突
公司用的mysql多,红帽光旁里集成的是mariadb(mysql是甲骨文的了)
卸载软不要用yum,要用rpm卸载(忽略依赖关系),不然会误珊服务
mysql-community-client-5.7.17-1.el7.x86_64.rpm
//是提供服务命令的包
mysql-community-server-5.7.17-1.el7.x86_64.rpm
//是提供服务的包
装包如果有依赖关系,看提示,再找包名 //yum list | grep 。。。
数据库目录:/var/lib/mysql/
启动服务初始化会在/var/lib/mysql下生成文件夹及文件
客户端访问数据库服务时传递进程数据文件:/var/lib/mysql/mysql.sock
mysql默认端口:3306
配置文件:/etc/my.cnf
日志文件:/var/log/mysqld.log
pid文件:/var/run/mysqld/mysqld.pid
数据库目录、进程 所有者所属组都是mysql
保证客户端可以通过进程把数据写入数据库里
*默认只允许数据库服务自己访问自己 //其他访问要授权
访问方式:命令行(运维人)、第三方软件图形(程序员用)
/etc/my.cof
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
#上面是mysql的官网
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql #数据库的目录
socket=/var/lib/mysql/mysql.sock #客户端访问数据库服务时传递进程数据信息的伪文件(服务启动时才有)
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
==log-error=/var/log/mysqld.log #错误日志
==pid-file=/var/run/mysqld/mysqld.pid #指定文件保存运行服务时进程的pid号
初始密码在/var/log/mysqld.log 里面
#grep password /var/log/mysqld.log //在:后面
[root@client mysql]# mysql -hlocalhost -uroot -p ‘q-whx%4S(sOc‘
第一次进去要改密码:>alter user root@”localhost” identified by “123qqq...A”; //新版密码有要求
>exit;
改过退出再进去就可以看库了
#mysql -hlocalhost -uroot -p‘123qqq...A‘ //密码复杂度可以修改
mysql> show databases;
+---------------------------+
| Database |
+----------------------------+
| information_schema |
| mysql |
| performance_schema|
| sys |
+----------------------------+
4 rows in set (0.00 sec)
修改密码复杂度:
mysql> show variables like "%password%";
+------------------------------------------------------+--------+
| Variable_name | Value |
+------------------------------------------------------+--------+
| default_password_lifetime | 0 |
| disconnect_on_expired_password | ON |
| log_builtin_as_identified_by_password | OFF |
| mysql_native_password_proxy_users | OFF |
| old_passwords | 0 |
| report_password | |
| sha256_password_proxy_users | OFF |
| validate_password_check_user_name | OFF |
| validate_password_dictionary_file | |
| validate_password_length | 8 | //密码长度,改成6就是6位数
| validate_password_mixed_case_count | 1 |
| validate_password_number_count | 1 |
| validate_password_policy | MEDIUM | //密码复杂度,改成0就是降低,会变成LOW
| validate_password_special_char_count | 1 |
+-------------------------------------------------------+--------+
14 rows in set (0.00 sec)
改密码复杂度(无要求)
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)
改长度6位数
mysql> set global validate_password_length=6;
Query OK, 0 rows affected (0.00 sec)
即可改简单密码
mysql> alter user root@"localhost" identified by "123456";
Query OK, 0 rows affected (0.00 sec)
[root@client mysql]# vim /etc/my.cnf //写入配置文件中永久配置,不然重启服务会恢复设置,写在[mysqld]下面
[mysqld]
validate_password_policy=0
validate_password_length=6
Root]#Systemctl restart mysqld //重启验证
[root@client mysql]# mysql -h localhost -u root -p123456 //密码可用
数据库就相当于文件夹
也可以直接在/varmysql> 也可以直接在/var/lib/mysql 下创建目录要设置属主和组为mysql)
运行环境的时候网站服务和数据库服务一起用(分两个服务器单独使用)
创建库不能用关键字,区分大小写,不能用特殊符号
库管理命令:
Show databases; //显示已有的库
Use han; //切换库
show tables; //查看已经有的表
Create database han; //创建库
Show tables; //显示已有的表
Drop database han; //删除库
select database(); //现实当前所在的库
创建库和表
mysql> create database teadb;
mysql> create table teadb.stuinfo( //表名为stuinfo,也可写相对路径直接写stuinfo
-> name char(20), //名称和设定字符
-> age int, //名称 类型为数字
-> homeaddr char(50)
-> );
Query OK, 0 rows affected (0.31 sec)
//先创建库再创建表
mysql> select * from teadb.stuinfo; //查看表信息内容
Empty set (0.01 sec)
mysql> insert into teadb.stuinfo values("bob",19,"shenzhen"),("tom",21,"guangzhou");
Query OK, 2 rows affected (0.03 sec)
Records: 2 Duplicates: 0 Warnings: 0
//创建记录 //values:值 //字符要引号
mysql> select * from teadb.stuinfo; //再查看记录
+----------+----------+-------------+
| name | age | homeaddr |
+----------+---------+---------------+
| bob | 19 | shenzhen |
| tom | 21 | guangzhou |
+-----------+---------+-------------+
2 rows in set (0.00 sec)
mysql> update teadb.stuinfo set age=35; //批量改表
mysql> update teadb.stuinfo set age=18 where name="bob"; //单独改表
mysql> delete from teadb.stuinfo where name="bob"; //删除name=bob的表
mysql> delete from teadb.stuinfo; //删除所有的表内容
mysql> desc teadb.stuinfo; //查看表结构
+---------------+------------+--------+--------+----------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+-------------+-------+--------+----------+-------+
| name | char(20) | YES | | NULL | |
| age | int(11) | YES | | NULL | |
| homeaddr | char(50) | YES | | NULL | |
+--------------+-------------+-------+--------+-----------+-------+
列名 字段类型 约束条件
mysql> drop tables teadb.stuinfo; //删除表,库还在
字符集 : 中文字符的集合
gb2312 :
utf8 : 可以写的汉字更多
mysql> use teadb;
创建表
mysql> create table t1(name char(10));
mysql> create table t2(name char(10));
mysql> show tables; //查看已经有的表
+---------------------+
| Tables_in_teadb |
+---------------------+
| t1 |
| t2 |
+---------------------+
mysql> show create table t2; //查看表的字符类型
+-------+-------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+-------------------------------------------------------------------------------------------+
| t2 | CREATE TABLE `t2` (
`name` char(10) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 | //默认字符类型
+-------+-------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> create table 学生表(姓名 char(20),性别 char(6))DEFAULT CHARSET=utf8; //创建中文表,指定字符类型为utf8
mysql> insert into 学生表 values("李斯","男"),("赵高","女"); //创建记录
mysql> select * from 学生表;
+---------+----------+
| 姓名 | 性别 |
+---------+----------+
| 李斯 | 男 |
| 赵高 | 女 |
+---------+----------+
2 rows in set (0.00 sec)
浮点型
创建t3表
mysql> create table t3(
-> age tinyint unsigned ,
-> pay float(7,2)
-> );
Query OK, 0 rows affected (0.22 sec)
//float(7,2)7位数2位小数
范围99999.99~ -99999.99
mysql> insert into t3 values(18,38000.88);
mysql> select * from t3;
+------+--------------+
| age | pay |
+------+--------------+
| 18 | 38000.88 |
+------+--------------+
1 row in set (0.00 sec)
//存什么数要考虑好,超过设置最大宽度存不上.
字符类型
一个英文字母就是一个字符
变长:输入多少就用多少不补空格(需要计算,会变慢)
varchar必须指宽度,否则报错
用的多的是char,char不指宽度默认宽度是1,速度快
mysql> create table t4(name char(4),homedir varchar(6));
mysql> desc t4; //查看表结构
+----------+---------------+-------+------+-------------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+----------------+-------+-----+-------------+-------+
| name | char(4) | YES | | NULL | |
| homedir | varchar(6) | YES | | NULL | |
+-----------+----------------+------+------+------------+-------+
//存超过设定的字符会报错
时间的用法
mysql> create table t5(name char(10),
-> birthday date,
-> start year,
-> uptime time,
-> party datetime
-> );
mysql> insert into t5 values("bob",19930702,1993,083000,20181015203000);
mysql> select * from t5;
+--------+--------------+---------+-----------+---------------------------+
| name | birthday | start | uptime | party |
+------+----------------+---------+------------+---------------------------+
| bob | 1993-07-02 | 1993 | 08:30:00 | 2018-10-15 20:30:00 |
+------+----------------+---------+------------+----------------------------+
//时间类型赋值一一对应
枚举
mysql> create table t6(
-> name char(10),
-> likes set("eat","sleep","game","file"),
-> sex enum("boy","girl","no"));
//设定值
mysql> insert into t6 values("bob","eat,sleep","boy"); //赋值,如果赋没有的值会报错
mysql> select * from t6;
+-------+-------------+------+
| name | likes | sex |
+-------+-------------+------+
| bob | eat,sleep | boy |
+-------+-------------+------+
标签:into 数据库软件 开源 mysql服务器 配置 要求 软件 ike user
原文地址:https://www.cnblogs.com/hanlongyu/p/9795037.html