Post Jobs

where关键字的区别

图片 7

创建两张表并插入一些数据

  1. ###  下载并安装MySQL官方的 Yum Repository

    wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
    

    在当前目录下会生成rpm文件

    图片 1

  2. ### 使用yum安装

    yum -y install mysql57-community-release-el7-10.noarch.rpm
    yum -y install mysql-community-server
    

     等待一段时间MySQL就安装完成了,然后是对MySQL的一些设置。

  3. ### 修改root密码

    安装成功后默认会创建一个root用户,并携带一个初始密码,需要修改初始密码,启动mysql

    systemctl start mysqld.service
    

    在Mysql的日志找出初始密码,命令如下

    grep "password" /var/log/mysqld.log
    

    图片 2

    通过下面的命令进入数据库

    mysql -uroot -p
    

    图片 3

    在mysql客户端连接环境下执行修改密码命令

    ALTER USER 'root'@'localhost' IDENTIFIED BY 'new@password';
    

    此时密码修改成功,重启mysql服务

    systemctl restart mysqld.service
    
  4. ###   修改字符集为UTF-8

    通过命令 mysql -uroot -p
    进入Mysql,注意是新密码,在mysql环境下通过如下命令查看字符集

    show variables like '%character%';
    

    图片 4

    我们看到上面的字符集不都是utf-8,现在我们在bash终端打开mysql配置文件

    vi /etc/my.cnf
    

    根据实际情况添加以下配置项

    #add by tangxiaobai
    character-set-server=utf8
    [client]
    default-character-set=utf8
    [mysql]
    default-character-set=utf8
    

    图片 5

    重启服务器,查看字符集有没有修改成功

    图片 6

    我们看到字符集修改成功

  5. ### 设置mysql支持远程连接

    到现在为止,我们的Mysql还不能远程连接访问,这里我们用的是该表法,登录mysql命令客户端,执行以下命令

    use mysql;
    update user set host = '%' where user = 'root';
    

    重启Mysql服务,用客户端连接工具测试

    图片 7

    我们看到mysql连接测试成功。

    但此时还有一个问题,就是因为安装了Yum
    Repository,以后每次yum操作都会自动更新,需要把这个卸载掉:

    yum -y remove mysql57-community-release-el7-10.noarch
    

错误1:

create table class(
  class_id int,
  class_name varchar(20),
  class_grade char(1)
);

insert into class values (1,'语文','A');
insert into class values (2,'数学','B');
insert into class values (3,'英语','C');

create table score(
  class_id int,
  stu_id varchar(20),
  Score int
);

insert into score values (1,'A001',91);
insert into score values (2,'A001',95);
insert into score values (1,'A002',82);
insert into score values (2,'A002',87);
insert into score values (3,'B003',65);

Executing the query “ALTER INDEX
[IX_liveConfigState_Service_ServiceId_…” failed with the
following error: “The index
“IX_liveConfigState_Service_ServiceId_GroupRightsVersion” on table
“liveConfigState_Service” cannot be reorganized because page level
locking is disabled.”. Possible failure reasons: Problems with the
query, “ResultSet” property not set correctly, parameters not set
correctly, or connection not established correctly.

 

 

查看表中的数据

解决方案:

mysql> select * from class;
+----------+------------+-------------+
| class_id | class_name | class_grade |
+----------+------------+-------------+
|        1 | 语文       | A           |
|        2 | 数学       | B           |
|        3 | 英语       | C           |
+----------+------------+-------------+
3 rows in set (0.00 sec)

mysql> select * from score;
+----------+--------+-------+
| class_id | stu_id | Score |
+----------+--------+-------+
|        1 | A001   |    91 |
|        2 | A001   |    95 |
|        1 | A002   |    82 |
|        2 | A002   |    87 |
|        3 | B003   |    65 |
+----------+--------+-------+
5 rows in set (0.00 sec)

mysql>

Query the indexes and tables list with follow query, then enable
their(index) page lock setting from property setting dialog.

 

 

比较下面几组查询结果
–如果你对left
join足够熟悉的话,先不要看结果,是否可以直接说出下面查询的结果

SELECT OBJECT_NAME(i.object_id) as TableName ,

mysql> select * from class A left join score B on A.class_id=B.class_id;
+----------+------------+-------------+----------+--------+-------+
| class_id | class_name | class_grade | class_id | stu_id | Score |
+----------+------------+-------------+----------+--------+-------+
|        1 | 语文       | A           |        1 | A001   |    91 |
|        2 | 数学       | B           |        2 | A001   |    95 |
|        1 | 语文       | A           |        1 | A002   |    82 |
|        2 | 数学       | B           |        2 | A002   |    87 |
|        3 | 英语       | C           |        3 | B003   |    65 |
+----------+------------+-------------+----------+--------+-------+
5 rows in set (0.00 sec)

mysql> select * from class A left join score B on A.class_id=B.class_id and 1=1;
+----------+------------+-------------+----------+--------+-------+
| class_id | class_name | class_grade | class_id | stu_id | Score |
+----------+------------+-------------+----------+--------+-------+
|        1 | 语文       | A           |        1 | A001   |    91 |
|        2 | 数学       | B           |        2 | A001   |    95 |
|        1 | 语文       | A           |        1 | A002   |    82 |
|        2 | 数学       | B           |        2 | A002   |    87 |
|        3 | 英语       | C           |        3 | B003   |    65 |
+----------+------------+-------------+----------+--------+-------+
5 rows in set (0.01 sec)

mysql> select * from class A left join score B on A.class_id=B.class_id and 1=0;
+----------+------------+-------------+----------+--------+-------+
| class_id | class_name | class_grade | class_id | stu_id | Score |
+----------+------------+-------------+----------+--------+-------+
|        1 | 语文       | A           |     NULL | NULL   |  NULL |
|        2 | 数学       | B           |     NULL | NULL   |  NULL |
|        3 | 英语       | C           |     NULL | NULL   |  NULL |
+----------+------------+-------------+----------+--------+-------+
3 rows in set (0.00 sec)

mysql> select * from class A left join score B on 1=0;
+----------+------------+-------------+----------+--------+-------+
| class_id | class_name | class_grade | class_id | stu_id | Score |
+----------+------------+-------------+----------+--------+-------+
|        1 | 语文       | A           |     NULL | NULL   |  NULL |
|        2 | 数学       | B           |     NULL | NULL   |  NULL |
|        3 | 英语       | C           |     NULL | NULL   |  NULL |
+----------+------------+-------------+----------+--------+-------+
3 rows in set (0.00 sec)

mysql> left join的最重要特点是:不管on后面是什么条件,都会返回左表中的所有行!

name as IndexName ,

发表评论

电子邮件地址不会被公开。 必填项已用*标注

相关文章

网站地图xml地图