数据库 二

数据库

[[email protected] ~]# systemctl stop firewalld.service

[[email protected] ~]# yum install mariadb-server -y

Loaded plugins: langpacks

rhel_dvd                                                 | 4.1 kB     00:00

Resolving Dependencies

--> Running transaction check

[[email protected] ~]# systemctl start mariadb

此时没有密码,可直接登陆

[[email protected] ~]# mysql -uroot

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 2

Server version: 5.5.35-MariaDB MariaDB Server

Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

MariaDB [(none)]>

[[email protected] ~]# vim /etc/my.cnf

10 skip-networking=1

[[email protected] ~]# systemctl restart mariadb

添加密码

[[email protected] ~]# mysql_secure_installation

/usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB

SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we‘ll need the current

password for the root user.  If you‘ve just installed MariaDB, and

you haven‘t set the root password yet, the password will be blank,

so you should just press enter here.

Enter current password for root (enter for none): ##空格(默认选项)

ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)

Enter current password for root (enter for none):

OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB

root user without the proper authorisation.

Set root password? [Y/n] ##空格(默认选项)

New password: ##输入密码

Re-enter new password: ##确认密码

Password updated successfully!

Reloading privilege tables..

... Success!

By default, a MariaDB installation has an anonymous user, allowing anyone

to log into MariaDB without having to have a user account created for

them.  This is intended only for testing, and to make the installation

go a bit smoother.  You should remove them before moving into a

production environment.

Remove anonymous users? [Y/n] ##空格(默认选项)

... Success!

Normally, root should only be allowed to connect from ‘localhost‘.  This

ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] ##空格(默认选项)

... Success!

By default, MariaDB comes with a database named ‘test‘ that anyone can

access.  This is also intended only for testing, and should be removed

before moving into a production environment.

Remove test database and access to it? [Y/n]  ##空格(默认选项)

- Dropping test database...

... Success!

- Removing privileges on test database...

... Success!

Reloading the privilege tables will ensure that all changes made so far

will take effect immediately.

Reload privilege tables now? [Y/n] ##空格(默认选项)

... Success!

Cleaning up...

All done!  If you‘ve completed all of the above steps, your MariaDB

installation should now be secure.

Thanks for using MariaDB!

用密码登陆

[[email protected] ~]# mysql -uroot -p123

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 11

Server version: 5.5.35-MariaDB MariaDB Server

Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

MariaDB [(none)]>

或者

[[email protected] ~]# mysql -uroot -p

Enter password:

MariaDB [(none)]> SHOW DATABASES; ##查看已有的数据库,分号结尾

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

| Database           |

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

| information_schema |

| mysql              |

| performance_schema |

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

3 rows in set (0.00 sec)

MariaDB [(none)]> USE mysql; ##使用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

MariaDB [mysql]> SHOW TABLES; ##显示库中的表

MariaDB [mysql]> DESC user; ##查看user表的数据结构

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

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

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

| Host                   | char(60)                          | NO   | PRI |         |       |

| User                   | char(16)                          | NO   | PRI |         |       |

| Password               | char(41)                          | NO   |     |         |       |

| Select_priv            | enum(‘N‘,‘Y‘)                     | NO   |     | N       |       |

| Insert_priv            | enum(‘N‘,‘Y‘)                     | NO   |     | N       |       |

| Update_priv            | enum(‘N‘,‘Y‘)                     | NO   |     | N       |       |

| Delete_priv            | enum(‘N‘,‘Y‘)                     | NO   |     | N       |       |

| Create_priv            | enum(‘N‘,‘Y‘)                     | NO   |     | N       |       |

| Drop_priv              | enum(‘N‘,‘Y‘)                     | NO   |     | N       |       |

| Reload_priv            | enum(‘N‘,‘Y‘)                     | NO   |     | N       |       |

| Shutdown_priv          | enum(‘N‘,‘Y‘)                     | NO   |     | N       |       |

| Process_priv           | enum(‘N‘,‘Y‘)                     | NO   |     | N       |       |

| File_priv              | enum(‘N‘,‘Y‘)                     | NO   |     | N       |       |

| Grant_priv             | enum(‘N‘,‘Y‘)                     | NO   |     | N       |       |

| References_priv        | enum(‘N‘,‘Y‘)                     | NO   |     | N       |       |

| Index_priv             | enum(‘N‘,‘Y‘)                     | NO   |     | N       |       |

| Alter_priv             | enum(‘N‘,‘Y‘)                     | NO   |     | N       |       |

| Show_db_priv           | enum(‘N‘,‘Y‘)                     | NO   |     | N       |       |

| Super_priv             | enum(‘N‘,‘Y‘)                     | NO   |     | N       |       |

| Create_tmp_table_priv  | enum(‘N‘,‘Y‘)                     | NO   |     | N       |       |

| Lock_tables_priv       | enum(‘N‘,‘Y‘)                     | NO   |     | N       |       |

| Execute_priv           | enum(‘N‘,‘Y‘)                     | NO   |     | N       |       |

| Repl_slave_priv        | enum(‘N‘,‘Y‘)                     | NO   |     | N       |       |

| Repl_client_priv       | enum(‘N‘,‘Y‘)                     | NO   |     | N       |       |

| Create_view_priv       | enum(‘N‘,‘Y‘)                     | NO   |     | N       |       |

| Show_view_priv         | enum(‘N‘,‘Y‘)                     | NO   |     | N       |       |

| Create_routine_priv    | enum(‘N‘,‘Y‘)                     | NO   |     | N       |       |

| Alter_routine_priv     | enum(‘N‘,‘Y‘)                     | NO   |     | N       |       |

| Create_user_priv       | enum(‘N‘,‘Y‘)                     | NO   |     | N       |       |

| Event_priv             | enum(‘N‘,‘Y‘)                     | NO   |     | N       |       |

| Trigger_priv           | enum(‘N‘,‘Y‘)                     | NO   |     | N       |       |

| Create_tablespace_priv | enum(‘N‘,‘Y‘)                     | NO   |     | N       |       |

| ssl_type               | enum(‘‘,‘ANY‘,‘X509‘,‘SPECIFIED‘) | NO   |     |         |       |

| ssl_cipher             | blob                              | NO   |     | NULL    |       |

| x509_issuer            | blob                              | NO   |     | NULL    |       |

| x509_subject           | blob                              | NO   |     | NULL    |       |

| max_questions          | int(11) unsigned                  | NO   |     | 0       |       |

| max_updates            | int(11) unsigned                  | NO   |     | 0       |       |

| max_connections        | int(11) unsigned                  | NO   |     | 0       |       |

| max_user_connections   | int(11)                           | NO   |     | 0       |       |

| plugin                 | char(64)                          | NO   |     |         |       |

| authentication_string  | text                              | NO   |     | NULL    |       |

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

42 rows in set (0.00 sec)

MariaDB [mysql]> SELECT USER,HOST,PASSWORD from user; ##查询user表中的USER,HOST,PASSWORD

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

| USER | HOST      | PASSWORD                                  |

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

| root | localhost | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |

| root | 127.0.0.1 | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |

| root | ::1       | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |

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

MariaDB [(none)]> CREATE DATABASE hello; ##创建hello数据库

Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> SHOW DATABASES;

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

| Database           |

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

| information_schema |

| hello              |

| mysql              |

| performance_schema |

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

MariaDB [hello]> CREATE TABLE westos(username varchar(15) not null,password varchar(15) not null); ##创建westos表,设定username,password的字段

Query OK, 0 rows affected (0.06 sec)

MariaDB [hello]> SHOW TABLES;

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

| Tables_in_hello |

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

| westos          |

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

1 row in set (0.00 sec)

MariaDB [hello]> DESC westos;

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

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

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

| username | varchar(15) | NO   |     | NULL    |       |

| password | varchar(15) | NO   |     | NULL    |       |

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

MariaDB [hello]> INSERT INTO westos VALUES (‘lee‘,‘123‘); ##在westos表中添加数据

Query OK, 1 row affected (0.04 sec)

MariaDB [hello]> SELECT * FROM westos;

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

| username | password |

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

| lee      | 123      |

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

1 row in set (0.00 sec)

MariaDB [hello]> UPDATE westos set password=‘234‘; ##将westos表中的password改为234

Query OK, 2 rows affected (0.35 sec)

Rows matched: 2  Changed: 2  Warnings: 0

MariaDB [hello]> SELECT * FROM westos;

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

| username | password |

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

| lee      | 234      |

| yz       | 234      |

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

2 rows in set (0.00 sec)

MariaDB [hello]> UPDATE westos set password=‘345‘ WHERE username=‘yz‘;

Query OK, 1 row affected (0.03 sec)

Rows matched: 1  Changed: 1  Warnings: 0

MariaDB [hello]> SELECT * FROM westos;

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

| username | password |

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

| lee      | 234      |

| yz       | 345      |

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

2 rows in set (0.00 sec) ##将westos表中username为yz的password改为345

MariaDB [hello]> DELETE FROM westos WHERE username=‘lee‘;

Query OK, 1 row affected (0.35 sec)

MariaDB [hello]> SELECT * FROM westos;

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

| username | password |

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

| yz       | 345      |

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

1 row in set (0.00 sec) ##删除westos表中username为lee的用户的所有信息

[[email protected] ~]# mysqldump -uroot -p123 hello > /mnt/hello.sql ##保存hello库中的数据到/mnt/hello.sql

MariaDB [hello]> DROP table westos; ##删除hello库中的westos表

Query OK, 0 rows affected (0.04 sec)

MariaDB [hello]> DROP database hello; ##删除数据库hello

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> SHOW DATABASES;

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

| Database           |

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

| information_schema |

| mysql              |

| performance_schema |

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

3 rows in set (0.00 sec)

[[email protected] ~]# mysql -uroot -p123 -e "CREATE DATABASE hello;" ##创建hello库

[[email protected] ~]# mysql -uroot -p123 hello < /mnt/hello.sql ##将/mnt/hello.sql的数据导入到hello库中

[[email protected] ~]# mysql -uroot -p123 -e "select * from hello.westos;"

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

| username | password |

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

| yz       | 345      |

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

[[email protected] ~]#

MariaDB [(none)]> CREATE USER [email protected]‘localhost‘ identified by ‘hello‘;

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> GRANT SELECT on hello.* TO [email protected];

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> SHOW GRANTS FOR [email protected];

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

| Grants for [email protected]                                                                                   |

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

| GRANT USAGE ON *.* TO ‘hello‘@‘localhost‘ IDENTIFIED BY PASSWORD ‘*6B4F89A54E2D27ECD7E8DA05B4AB8FD9D1D8B119‘ |

| GRANT SELECT ON `hello`.* TO ‘hello‘@‘localhost‘                                                             |

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

MariaDB [(none)]> GRANT SELECT,INSERT,UPDATE,DELETE on hello.* TO [email protected]

-> ;

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> SHOW GRANTS FOR [email protected];+--------------------------------------------------------------------------------------------------------------+

| Grants for [email protected]                                                                                   |

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

| GRANT USAGE ON *.* TO ‘hello‘@‘localhost‘ IDENTIFIED BY PASSWORD ‘*6B4F89A54E2D27ECD7E8DA05B4AB8FD9D1D8B119‘ |

| GRANT SELECT, INSERT, UPDATE, DELETE ON `hello`.* TO ‘hello‘@‘localhost‘                                     |

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

2 rows in set (0.00 sec)

[[email protected] ~]# mysqladmin -uroot -p123 password hello ##修改登陆密码

[[email protected] ~]# mysql -uroot -p

Enter password:

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 24

Server version: 5.5.35-MariaDB MariaDB Server

忘记密码

[[email protected] ~]# systemctl stop mariadb.service

[[email protected] ~]# mysqld_safe --skip-grant-tables&

[1] 5917

[[email protected] ~]# 161207 23:09:04 mysqld_safe Logging to ‘/var/log/mariadb/mariadb.log‘.

161207 23:09:04 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

MariaDB [(none)]> UPDATE mysql.user set Password=password(‘hello‘) WHERE User=‘root‘;

Query OK, 3 rows affected (0.33 sec)

Rows matched: 3  Changed: 3  Warnings: 0

MariaDB [(none)]> quit

[[email protected] ~]# fg

mysqld_safe --skip-grant-tables

^Z

[1]+  Stopped                 mysqld_safe --skip-grant-tables

[[email protected] ~]#

[[email protected] ~]# ps aux | grep mysql

root      5917  0.0  0.0 113252  1552 pts/0    T    23:09   0:00 /bin/sh /usr/bin/mysqld_safe --skip-grant-tables

mysql     6072  0.1  4.7 859056 90368 pts/0    Sl   23:09   0:00 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --skip-grant-tables --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/run/mariadb/mariadb.pid --socket=/var/lib/mysql/mysql.sock

root      6182  0.0  0.0 112640   936 pts/0    S+   23:12   0:00 grep --color=auto mysql

[[email protected] ~]# kill -9 6072

[[email protected] ~]# systemctl start mariadb

[[email protected] ~]# yum install httpd -y

下载phpMyAdmain-3.4.0-all-languages.tar.bz2

[[email protected] html]# tar jxf phpMyAdmain-3.4.0-all-languages.tar.bz2

[[email protected] html]# mv phpMyAdmain-3.4.0-all-languages saozhu

[[email protected] html]# cd saozhu/

[[email protected] saozhu]# cp -p config.sample.inc.php config.inc.php

[[email protected] saozhu]# vim config.inc.php

17 $cfg[‘blowfish_secret‘] = ‘westos‘; /* YOU MUST FILL IN THIS FOR COOKIE AUTH    ! */

[[email protected] saozhu]# systemctl stop firewalld.service

[[email protected] saozhu]# systemctl start httpd

[[email protected] saozhu]# yum install php -y

[[email protected] ~]# mysql -uroot -phello -e "select * from saozhu.vuser;"

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

| username         | password | domain     | maildir           |

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

| [email protected] | 123      | westos.org | westos.org/admin/ |

| [email protected]   | 123      | redhat.org | westos.org/lee/   |

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

时间: 2024-10-13 22:57:21

数据库 二的相关文章

JAVA使用JDBC连接MySQL数据库 二(2)

本文是对 <JAVA使用JDBC连接MySQL数据库 二>的改进. 上节使用的是PreparedStatement来执行数据库语句,但是preparedStatement需要传递一个sql语句参数,才能创建.然而,DBHelper类只是起到打开和关闭数据库的作用,所以sql语句是要放到应用层部分的,而不是放到DBHelper类中. 而statment不需要传递一个sql语句参数,就能创建. 修改部分如下: public class DBHelper { String driver = &quo

MySQL学习笔记_12_Linux下C++/C连接MySQL数据库(二) --返回数据的SQL

 Linux下C++/C连接MySQL数据库(二) --返回数据的SQL 引: 返回数据的SQL是指通过查询语句从数据库中取出满足条件的数据记录 从MySQL数据库值哦功能检索数据有4个步骤: 1)发出查询 2)检索数据 3)处理数据 4)整理所需要的数据 用mysql_query()发出查询,检索数据可以使用mysql_store_result()或mysql_use_result(),取决与怎样检索数据,接着是调用mysql_fetch_row()来处理数据,最后,还必须调用mysql_

mySQL数据库二:命令行的使用

在做整理的时候,上一篇刚开始只是简单的做了个数据类型的开头,在这里简单说一下mySQL的使用以及它的命令行 1.准备工作 有一个好的开发工具可以几何倍数的增加我们的工作效率,所以,工具是必不可少的,首先我们需要下载一个wamp(window系统专用)的工具,苹果电脑为Mamp,如下图所示 下载完成之后双击,可以看到在电脑屏幕的右下方出现一个卡哇伊的“W”图标,对,是他是他就是他,当他从红变成绿色的时候,说明你的准备工作已经完成了,开始你的mySQL之旅吧 2. 操作方法一: 左键点击那个可爱的“

MySQL数据库(二)

事务 数据库开启事务命令 #start transaction 开启事务 #Rollback 回滚事务,即撤销指定的sql语句(只能回退insert delete update语句),回滚到上一次commit的位置 #Commit 提交事务,提交未存储的事务 #savepoint 保留点 ,事务处理中设置的临时占位符 你可以对它发布回退(与整个事务回退不同) 事务操作演示 create table account( id int, name varchar(32), balance double

一次数据库|二次数据库|

生物医学大数据-组学数据资源 困境: 经过human genome project之后得到了Book of life,但是测得base仅仅是生物信息学分析的开始,因为发现了数据的几个重要特点.首先是数据量过大,虽然科学家想通过不同组学角度(组学也随着数据量的增多层层细化和深入)来简化和系统解读过程,但是由于生物数据所对应的生物个体本身的结构复杂和高度特异,所以数据量的增大并没有带来数据质量的提升,反而提高了解读难度(eg,蛋白质结构相同但基因组不同的概率小,但是genome基数大,所以依据E=N

MySQL数据库&lt;二&gt;

yum安装mysql      MySQL的安装方式有很多,现在我们主要讨论yum安装mysql. 1. MySQL官网 www.mysql.com  可下载最新版本 2.MySQL需要安装的包 mysql-server 服务端 mysql    客户端 mysql-devel    库文件 3.安装MySQL数据库: yum list|grep mysql      #查看是否装有mysql包 rpm -qa |grep mysql-server      #查看是否已安装mysql包   y

TiDB 分布式数据库(二)

# # TiDB :A Distributed SQL Database # github :https://github.com/pingcap/tidb # doc : https://github.com/pingcap/docs-cn # #架构 Name Host IP Services node1 192.168.174.134 PD, TiDB node2 192.168.174.136 TiKV1 node3 192.168.174.137 TiKV2 node4 192.168

PHP MySQL数据库二

三.MySQL常用函数 文本函数 函数 用法 描述 CONCAT() CONCAT(x,y,...) 创建形如xy的新字符串 LENGTH() LENGTH(column) 返回列中储存的值的长度 LEFT() LEFT(column,x) 从列的值中返回最左边的x个字符 RIGHT() RIGHT(column,x) 从列的值中返回最右边的x个字符 TRIM() TRIM(column) 从存储的值删除开头和结尾的空格 UPPER() UPPER(column) 把存储的字符串全部大写 LOW

数据库二

1.数据约束 a.默认值约束 默认值(default) CREATE TABLE test( NAME VARCHAR(20), gender VARCHAR(2) DEFAULT '男' ) 注:当前没有插入默认值字段的时候,默认值才会起作用 b.非空约束 非空(not null) CREATE TABLE test( NAME VARCHAR(20) NOT NULL, gender VARCHAR(2) ) 注:不能不插入值,不能插入null c.唯一约束 唯一(unique) CREAT