创建数据库、表并将值插入表中
登录到 mysql
# mysql -u root -p Enter Pasword: Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 1108 Server version: 5.0.77 Source distribution Type 'help;' or 'h' for help. Type 'c' to clear the buffer. mysql> show databases; -- 列出所有的数据库 +--------------------+ | Database | +--------------------+ | information_schema | | mysql | +--------------------+
mysql> create database mycomp;
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| mycomp |
+--------------------+
mysql> use mycomp; --"连接到指定的数据库"
Database changed
mysql> create table employee (SerialNo varchar(3),Name char(20),Age varchar(2));
Query OK,
0 rows affected (0.01 sec)
mysql> describe employee;
+----------+------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+------------+------+-----+---------+-------+
| SerialNo | varchar(3) | YES | | NULL | |
| Name | char(20) | YES | | NULL | |
| Age | varchar(2) | YES | | NULL | |
+----------+------------+------+-----+---------+-------+
3 rows in set (0.00 sec)
mysql> show tables; --列出所选数据库中的可用表
+----------------+
| Tables_in_test |
+----------------+
| employee |
+----------------+
1 row in set (0.00 sec)
mysql> INSERT INTO employee VALUES ('1','jack Prasad','23');
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO employee VALUES ('2','cherry Dubey','24');
Query OK, 1 row affected (0.00 sec)
mysql> SELECT * from employee;
+----------+---------------+------+
| SerialNo | Name | Age |
+----------+---------------+------+
| 1 | jack Prasad | 23 |
| 2 | cherry Dubey | 24 |
+----------+---------------+------+
2 rows in set (0.00 sec)
mysql> quit Bye
重启mysql数据库
# /etc/init.d/mysqld restart 或者 # service mysqld restart
确保即使在重新启动 linux 机器后,数据库也是启动的
# chkconfig mysqld on
安装 MySQL
确保机器上安装了 mysql 包,我们可以使用它进行检查
# rpm -qa | grep mysql
如果没有出现任何问题,我们可以使用手动安装
# yum install mysql
默认安装了软件包后:
管理员用户:root
密码:空白
我们必须为 root 分配一个密码
# mysqladmin -u root password 'new-password'
或者
# mysql -u root -p
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 1108
Server version: 5.0.77 Source distribution
Type 'help;' or 'h' for help. Type 'c' to clear the buffer.
mysql> USE mysql;
mysql> UPDATE user SET Password=PASSWORD('new-password') WHERE user='root';
mysql> FLUSH PRIVILEGES;
下面示例是在 Red Hat Linux 上创建 MySQL 数据库,因此请根据Linux发行版修改相应的命令。
日期:2020-06-02 22:18:29 来源:oir作者:oir
