您当前的位置: 首页 > 学无止境 > 心得笔记 网站首页心得笔记
马哥linux运维学习笔记-MySQL初步,数据类型及SQL语句
发布时间:2019-02-08 09:06:40编辑:雪饮阅读()
mysql的安装:
挂载redhat5.8的i386光盘将其中的mysql和mysql-server两个包安装即可,安装后service mysqld start即可初始化数据,默认root的密码为空.服务启动后通过命令netstat -ntlp可以看到默认的监听端口是3306
数据库与目录的关系:
在默认的数据库安装目录中建立一个文件夹,则在数据库控制台上可以看到以该文件夹名称的一个数据库存在,如
[root@localhost test]# mkdir /var/lib/mysql/mydb
[root@localhost test]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
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 |
| mydb |
| mysql |
| test |
+--------------------+
4 rows in set (0.00 sec)
表修改
添加字段
mysql> alter table students add course varchar(100);
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
修改字段
mysql> alter table students change course Course varchar(100) after name;
Query OK, 0 rows affected (0.00 sec)
Records: 0 Duplicates: 0 Warnings: 0
用户与授权
创建用户
mysql> create user 'jerry'@'%' identified by 'jerry';
Query OK, 0 rows affected (0.00 sec)
显示权限
mysql> show grants for 'jerry'@'%';
+-----------------------------------------------------------------------------+
| Grants for jerry@% |
+-----------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'jerry'@'%' IDENTIFIED BY PASSWORD '7e82afb618ffeb73' |
+-----------------------------------------------------------------------------+
1 row in set (0.00 sec)
授权
mysql> grant all privileges on testdb.* to 'jerry'@'%';
Query OK, 0 rows affected (0.00 sec)
远程连接:
[root@localhost test]# mysql -u jerry -h 192.168.1.8 -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
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 |
| test |
| testdb |
+--------------------+
3 rows in set (0.01 sec)
mysql>
关键字词:mysql,linux,sql