首页 > 代码库 > MySQL学习笔记-安装和基本操作
MySQL学习笔记-安装和基本操作
1.安装MySQL
1 # yum -y install mysql mysql-server mysql-devel
1 vi /etc/my.conf2 [mysqld]3 default-character-set=utf84 character_set_server=utf85 [client]6 default-character-set=utf8
2.启动和停止MySQL服务:
# service mysqld start # service mysqld stop
3.登录和退出MySQL,设置mysql密码,允许远程登录mysql:
1 # mysql -uroot //登录mysql
1 mysql> exit //退出mysql
mysql>; USE mysql; mysql>; UPDATE user SET Password=PASSWORD(‘newpassword‘) WHERE user=‘root‘; mysql>; FLUSH PRIVILEGES;
5.允许远程登录
1 mysql -u root -p
Enter Password: <your new password> mysql>GRANT ALL PRIVILEGES ON *.* TO ‘用户名‘@‘%‘ IDENTIFIED BY ‘密码‘ WITH GRANT OPTION;
6.修改MySQL提示符
1 # mysql -uroot -proot --prompt ‘<提示符>’ //在windows中不用‘’
mysql> prompt <提示符>
5.MySQL提示符:
\D | 完整的日期 | |
\d | 当前数据库 | |
\h | 服务器名称 | |
\u | 当前用户 | |
1 # mysql -uroot --prompt ‘\u@\h \d‘2 root@localhost (none)
mysql> prompt \u@\h \d>PROMPT set to ‘\u@\h \d>‘root@localhost (none)>
6.MySQL常用命令
mysql> SELECT VERSION();+-----------+| VERSION() |+-----------+| 5.1.71 |+-----------+1 row in set (0.00 sec)
mysql> SELECT USER(); +----------------+| USER() |+----------------+| root@localhost |+----------------+1 row in set (0.00 sec)
mysql> SELECT NOW(); +---------------------+| NOW() |+---------------------+| 2016-11-20 21:32:55 |+---------------------+1 row in set (0.00 sec)
7.MySQL语句规范:
mysql> CREATE DATABASE test1;
mysql> CREATE DATABASE IF NOT EXISTS test1; Query OK, 1 row affected, 1 warning (0.00 sec)
mysql> SHOW WARNINGS;+-------+------+-----------------------------------------------------------------------------------------------------------------------------------------------------------+| Level | Code | Message |+-------+------+-----------------------------------------------------------------------------------------------------------------------------------------------------------+| Error | 1064 | You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘WARNING‘ at line 1 |+-------+------+-----------------------------------------------------------------------------------------------------------------------------------------------------------+1 row in set (0.00 sec)
mysql> SHOW DATABASES;+--------------------+| Database |+--------------------+| information_schema || mysql || test || test1 |+--------------------+4 rows in set (0.00 sec)
mysql> SHOW CREATE DATABASE test1;+----------+----------------------------------------------------------------+| Database | Create Database |+----------+----------------------------------------------------------------+| test1 | CREATE DATABASE `test1` /*!40100 DEFAULT CHARACTER SET utf8 */ |+----------+----------------------------------------------------------------+1 row in set (0.00 sec)
mysql> CREATE DATABASE IF NOT EXISTS test2 CHARACTER SET gbk; Query OK, 1 row affected (0.00 sec) mysql> SHOW CREATE DATABASE test2;+----------+---------------------------------------------------------------+| Database | Create Database |+----------+---------------------------------------------------------------+| test2 | CREATE DATABASE `test2` /*!40100 DEFAULT CHARACTER SET gbk */ |+----------+---------------------------------------------------------------+1 row in set (0.00 sec)
mysql> ALTER DATABASE test2 CHARACTER SET utf8;
mysql> ALTER DATABASE test2 CHARACTER SET = utf8;
mysql> DROP DATABASE test1;
本文出自 “谢育政” 博客,请务必保留此出处http://kurolz.blog.51cto.com/11433546/1929129
MySQL学习笔记-安装和基本操作
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。