标签:
[root@localhost ~]# rpm -qa | grep mysql
[root@localhost ~]# rpm -e --nodeps mysql此时,系统中已经不存在了MySQL的安装记录。
[root@localhost ~]#yum list | grep mysql
[root@localhost ~]# yum install -y mysql-server mysql mysql-devel
[root@localhost ~]# chkconfig mysqld on [root@localhost ~]# chkconfig --list | grep mysql mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:of
[root@localhost ~]# cat /etc/my.cnf [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock user=mysql # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 [mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid [root@localhost ~]#
[root@localhost mysql]# cd /var/lib/mysql [root@localhost mysql]# ls -l total 20500 -rw-r--r--. 1 root root 10717 May 13 10:34 create -rw-rw----. 1 mysql mysql 10485760 May 13 10:27 ibdata1 -rw-rw----. 1 mysql mysql 5242880 May 13 10:27 ib_logfile0 -rw-rw----. 1 mysql mysql 5242880 May 13 10:27 ib_logfile1 drwx------. 2 mysql mysql 4096 May 13 10:27 mysql srwxrwxrwx. 1 mysql mysql 0 May 13 10:27 mysql.sock drwx------. 2 mysql mysql 4096 May 13 10:27 test [root@localhost mysql]#
[root@localhost mysql]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 21 Server version: 5.1.73 Source distribution Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> create database yr; Query OK, 1 row affected (0.00 sec) mysql> exit Bye [root@localhost mysql]#首先,我们用root账户登录数据库,可以看到mysql> 命令提示符号,执行创建数据库命令create database name; 得到创建成功消息,退出数据库使用命令exit。
[root@localhost mysql]# ls -l total 20504 -rw-r--r--. 1 root root 10717 May 13 10:34 create -rw-rw----. 1 mysql mysql 10485760 May 13 10:27 ibdata1 -rw-rw----. 1 mysql mysql 5242880 May 13 10:27 ib_logfile0 -rw-rw----. 1 mysql mysql 5242880 May 13 10:27 ib_logfile1 drwx------. 2 mysql mysql 4096 May 13 10:27 mysql srwxrwxrwx. 1 mysql mysql 0 May 13 10:27 mysql.sock drwx------. 2 mysql mysql 4096 May 13 10:27 test drwx------. 2 mysql mysql 4096 May 13 14:41 yr [root@localhost mysql]#(2)建表并添加数据
[root@localhost mysql]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 23 Server version: 5.1.73 Source distribution Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> use yr; Database changed mysql> create table user( -> Id INTEGER AUTO_INCREMENT NOT NULL PRIMARY KEY, -> Name VARCHAR(50), -> age INTEGER); Query OK, 0 rows affected (0.07 sec) mysql>
mysql> insert into user(Id , Name , age)values(1,"aa",20); Query OK, 1 row affected (0.10 sec) mysql> insert into user(Id , Name , age)values(2,"bb",21); Query OK, 1 row affected (0.00 sec) mysql> select Id , Name , age from user; +----+------+------+ | Id | Name | age | +----+------+------+ | 1 | aa | 20 | | 2 | bb | 21 | +----+------+------+(3)从数据库表中删除数据
mysql> delete from user where Id=1; Query OK, 1 row affected (0.05 sec) mysql> select Id , Name , age from user; +----+------+------+ | Id | Name | age | +----+------+------+ | 2 | bb | 21 | +----+------+------+ 1 row in set (0.00 sec) mysql>
mysql> drop table user; Query OK, 0 rows affected (0.02 sec)
mysql> drop database yr; Query OK, 0 rows affected (0.28 sec) mysql> exit Bye [root@localhost mysql]# ll total 20500 -rw-r--r--. 1 root root 10717 May 13 10:34 create -rw-rw----. 1 mysql mysql 10485760 May 13 10:27 ibdata1 -rw-rw----. 1 mysql mysql 5242880 May 13 10:27 ib_logfile0 -rw-rw----. 1 mysql mysql 5242880 May 13 10:27 ib_logfile1 drwx------. 2 mysql mysql 4096 May 13 10:27 mysql srwxrwxrwx. 1 mysql mysql 0 May 13 10:27 mysql.sock drwx------. 2 mysql mysql 4096 May 13 10:27 test [root@localhost mysql]#
菜鸟的《Linux程序设计》学习(8):MySQL数据库安装、配置及基本操作
标签:
原文地址:http://blog.csdn.net/fly_yr/article/details/45690497