MySQL学习笔记-安装和基本操作
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 ‘\[email protected]\h \d‘2 [email protected] (none)
mysql> prompt \[email protected]\h \d>PROMPT set to ‘\[email protected]\h \d>‘[email protected] (none)>
6.MySQL常用命令
mysql> SELECT VERSION();+-----------+| VERSION() |+-----------+| 5.1.71 |+-----------+1 row in set (0.00 sec)
mysql> SELECT USER(); +----------------+| USER() |+----------------+| [email protected] |+----------------+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学习笔记-安装和基本操作的主要内容,如果未能解决你的问题,请参考以下文章