mysql安装与初始化密码、表结构与表字段

scp'/root/桌面/数据库/mysql-5.7.17-1.el7.x86_64.rpm-bundle.tar' [email protected]:/root


[root@rootroom9pc01~]# vim /etc/bashrc

[root@rootroom9pc01~]# . /etc/bashrc

[root@rootroom9pc01~]# host50

[email protected]'spassword:

Lastlogin: Wed Jun 13 17:39:37 2018 from 192.168.4.254

[root@host50~]# tar -xf mysql-5.7.17-1.el7.x86_64.rpm-bundle.tar

[root@host50~]# ls *.rpm



装包

rpm-Uvh mysql-community-*.rpm

yum-y install perl-JSON

rpm-Uvh mysql-community-*.rpm

ls

rm-rf mysql-community-server-minimal-5.7.17-1.el7.x86_64.rpm

rpm-Uvh mysql-community-*.rpm

[root@host50 ~]# rpm-qa | grep -i mysql -i 忽略大小写

修改配置文件 /etc/my.cnf

Systemctlstatus mysqld

/usr/lib/systemd/system/mysqld.service


数据库目录 /var/lib/mysql


[root@host50mysql]# systemctl start mysqld

[root@host50mysql]# ls

auto.cnf ib_buffer_pool mysql public_key.pem

ca-key.pem ibdata1 mysql.sock server-cert.pem

ca.pem ib_logfile0 mysql.sock.lock server-key.pem

client-cert.pem ib_logfile1 performance_schema sys

client-key.pem ibtmp1 private_key.pem

[root@host50mysql]# systemctl enable mysqld

[root@host50mysql]# systemctl status mysqld


默认端口号:3306

进程名:mysqld ps -C mysqld

[root@host50mysql]# ps -C mysqld

[root@host50mysql]# netstat -utnlp | grep mysqld

[root@host50mysql]# netstat -utnlp | grep :3306


传输协议 TCP

[root@host50mysql]# ps aux | grep mysqld

mysql 2236 0.0 16.9 1119216 171844 ? Sl 10:22 0:00/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

root 2353 0.0 0.0 112676 984 pts/0 R+ 10:29 0:00 grep--color=auto mysqld


[root@host50mysql]# grep mysql /etc/passwd

mysql:x:27:27:MySQLServer:/var/lib/mysql:/bin/false

[root@host50mysql]# grep mysql /etc/group

mysql:x:27:


[root@host50mysql]# ls -ld /var/lib/mysql

drwxr-x--x.5 mysql mysql 4096 61410:22 /var/lib/mysql


[root@host50mysql]# ll

总用量122952

-rw-r-----.1 mysql mysql 56 61410:21 auto.cnf

-rw-------.1 mysql mysql 1679 61410:22 ca-key.pem

-rw-r--r--.1 mysql mysql 1074 61410:22 ca.pem

-rw-r--r--.1 mysql mysql 1078 61410:22 client-cert.pem

-rw-------.1 mysql mysql 1679 61410:22 client-key.pem

-rw-r-----.1 mysql mysql 413 61410:22 ib_buffer_pool

-rw-r-----.1 mysql mysql 12582912 61410:22 ibdata1

-rw-r-----.1 mysql mysql 50331648 61410:22 ib_logfile0

-rw-r-----.1 mysql mysql 50331648 61410:21 ib_logfile1

-rw-r-----.1 mysql mysql 12582912 61410:22 ibtmp1

drwxr-x---.2 mysql mysql 4096 61410:21 mysql

srwxrwxrwx.1 mysql mysql 0 61410:22 mysql.sock

-rw-------.1 mysql mysql 5 61410:22 mysql.sock.lock

drwxr-x---.2 mysql mysql 8192 61410:21 performance_schema

-rw-------.1 mysql mysql 1675 61410:22 private_key.pem

-rw-r--r--.1 mysql mysql 451 61410:22 public_key.pem

-rw-r--r--.1 mysql mysql 1078 61410:22 server-cert.pem

-rw-------.1 mysql mysql 1675 61410:22 server-key.pem

drwxr-x---.2 mysql mysql 8192 61410:22 sys


Rm-rf *.rpm

Tar-xvf xxx.tar

Rm-rf mysql-connunity-server-minimal-5.7.17-1.el7.x86_64.rpm

Yum-y install perl-JSON

Rpm-Uvh mysql-community-*.rpm

Systemctlstart mysqld


[root@host50mysql]# systemctl status mysqld

[root@host50mysql]# ps -C mysqld

PIDTTY TIME CMD

2236? 00:00:01 mysqld


[root@host50mysql]# ss -utnlp | grep :3306

tcp LISTEN 0 80 :::3306 :::* users:(("mysqld",pid=2236,fd=22))





Php java

Nginx apache tomcat

LNMP LAMP

Mysql Mongodb

游戏 购物 论坛 金融


MySQL-5.7

把数据存储到数据库服务器上的过程

1连接数据库服务器 (命令连接 图形工具)

Mysql-hlocalhost -uroot -p密码

初始密码在:Ls/var/log/mysqld.log

Grep-i password /var/log/mysqld.log


2选择库 (文件夹)

3建表

4插入记录 (行)

5断开连接

RDBMS关系型数据库


Rpm-qa | grep -i mysql

[root@host50mysql]# rpm -qa |grep -i mysql

mysql-community-client-5.7.17-1.el7.x86_64


[root@host50mysql]# which mysql

/usr/bin/mysql

[root@host50mysql]# rpm -qf /usr/bin/mysql

mysql-community-client-5.7.17-1.el7.x86_64


[root@host51mysql]# rpm -qf /bin/mysql

mysql-community-client-5.7.17-1.el7.x86_64


[root@host50mysql]# grep -i password /var/log/mysqld.log



2018-06-14T02:21:42.501465Z1 [Note] A temporary password is generated for root@localhost:Cw5Hfukhjt<t

[root@host50mysql]# mysql -hlocalhost -uroot -p'Cw5Hfukhjt<t'


Ctrl+L

\q

Quit;


SQL:结构化查询命令

mysql>show databases;

ERROR1820 (HY000): You must reset your password using ALTER USER statementbefore executing this statement.


Setglobal validate_password_policy=0; 验证策略

Setglobal validate_password_length=6; 密码验证

Alteruser root@”localhost” identified by “123456”;



Showdatabases;

Information_schema 虚拟库


Createdatabase db1;


Cd/var/lib/mysql

[root@rootroom9pc01~]# host51

[email protected]'spassword:


[root@rootroom9pc01~]# host50

[email protected]'spassword:

Lastlogin: Thu Jun 14 09:42:47 2018 from 192.168.4.254

[root@host50~]# ls /var/lib/mysql

auto.cnf db1 ibtmp1 private_key.pem

ca-key.pem ib_buffer_pool mysql public_key.pem

ca.pem ibdata1 mysql.sock server-cert.pem

client-cert.pem ib_logfile0 mysql.sock.lock server-key.pem

client-key.pem ib_logfile1 performance_schema sys

[root@host50~]#


永久生效

Vim/etc/my.cnf


[mysqld]

validate_password_policy=0

validate_password_length=6



Systemctlstop mysqld

Systemctlstart mysqld

Systemctlstatus mysqld

[root@host50~]# mysql -hlocalhost -uroot -p123456


Showdatabases; 显示已有的库

Use库名;

Selectdatabase(); 显示当前所在的库

Createdatabase 库名;

Dropdatabase 库名;


Createt1(

Namechar(15);

Classchar(7)

);


mysql>desc t1;


Select* from c1;


Insertinto t1 values(“cuihzhiwei”,”nsd1803”),(“bob”,”nsd1803”);

Updatet1 set class=”nsd1809”;

Deletefrom t1;

Droptable t1;


createtable 学生信息表2(姓名 char(15),班级 char(7)) DEFAULTCHARSET=utf8;

QueryOK, 0 rows affected (0.26 sec)


mysql>insert into 学生信息表2values("崔志伟","nsd1802");


mysql>show create table 学生信息表2;

+------------------+------------------------------------------------------------------------------------------------------------------------------------------+

|Table | Create Table |

+------------------+------------------------------------------------------------------------------------------------------------------------------------------+

|学生信息表2 | CREATE TABLE `学生信息表2`(

`姓名`char(15) DEFAULT NULL,

`班级`char(7) DEFAULT NULL

)ENGINE=InnoDB DEFAULT CHARSET=utf8 |

+------------------+------------------------------------------------------------------------------------------------------------------------------------------+

1row in set (0.00 sec)


mysql>


Createtable db1.t2(

Leveltinyint

);

Insertinto t2 values(251);


Createtable db1.t3(

Leveltinyint unsigned

);

Insertinto t3 values(256);


Createtable db1.t4(

Paydouble(5,2)

);


Createtable t5(

Namechar(15),

Emailvarchar(30)

);


Insertinto t5 values(“bob”,”[email protected]”),(“lucy”,”[email protected]”);


Insertinto t5 values(“pangliing8888888888888888888”,”[email protected]”);


Createtable t6(

Namechar(15),

Agetinyint unsigned,

Payfloat(7,2),

Sexenum(“boy”,”girl”,”no”),

Likesset(“woman”,”money”,”game”,”eat”)

);


mysql>desc t6

->;

+-------+-----------------------------------+------+-----+---------+-------+

|Field | Type | Null | Key | Default |Extra |

+-------+-----------------------------------+------+-----+---------+-------+

|Name | char(15) | YES | | NULL | |

|Age | tinyint(3) unsigned | YES | | NULL | |

|Pay | float(7,2) | YES | | NULL | |

|Sex | enum('boy','girl','no') | YES | | NULL | |

|Likes | set('woman','money','game','eat') | YES | | NULL | |

+-------+-----------------------------------+------+-----+---------+-------+

5rows in set (0.00 sec)


insertinto t6 values("bob",21,20000,"no","eat,game");

insertinto t6 values("bob1",21,20000,"man","eat,game");

insertinto t6 values("bob2",21,20000,"boy","eat,game");

insertinto t6 values("bob",21,20000,"1","eat,game");


mysql>create table t7(

->name char(15),

->syear year,

->birthday date,

->up_class time,

->party datetime

->);

QueryOK, 0 rows affected (0.44 sec)


mysql>desc t7;

+----------+----------+------+-----+---------+-------+

|Field | Type | Null | Key | Default | Extra |

+----------+----------+------+-----+---------+-------+

|name | char(15) | YES | | NULL | |

|syear | year(4) | YES | | NULL | |

|birthday | date | YES | | NULL | |

|up_class | time | YES | | NULL | |

|party | datetime | YES | | NULL | |

+----------+----------+------+-----+---------+-------+

5rows in set (0.00 sec)


mysql>insert into t7 values("yaya",1990,20181120,083000,20180618213000);

QueryOK, 1 row affected (0.08 sec)


mysql>select * from t7;

+------+-------+------------+----------+---------------------+

|name | syear | birthday | up_class | party |

+------+-------+------------+----------+---------------------+

|yaya | 1990 | 2018-11-20 | 08:30:00 | 2018-06-18 21:30:00 |

+------+-------+------------+----------+---------------------+

1row in set (0.00 sec)


mysql>

mysql>insert into t7 values("yaya",53,20181120,083000,20181118213000);

QueryOK, 1 row affected (0.04 sec)


mysql>insert into t7 values("yaya",1953,20181120,083000,20181118213000);

QueryOK, 1 row affected (0.04 sec)


mysql>


mysql>select * from t7;

+------+-------+------------+----------+---------------------+

|name | syear | birthday | up_class | party |

+------+-------+------------+----------+---------------------+

|yaya | 1990 | 2018-11-20 | 08:30:00 | 2018-06-18 21:30:00 |

|yaya | 2053 | 2018-11-20 | 08:30:00 | 2018-11-18 21:30:00 |

|yaya | 1953 | 2018-11-20 | 08:30:00 | 2018-11-18 21:30:00 |

+------+-------+------------+----------+---------------------+

3rows in set (0.00 sec)


mysql>



猜你喜欢

转载自blog.csdn.net/weixin_40018205/article/details/80945100