经过安装后的初始化过程,MySQL数据库的默认管理员用户名为“root”,密码为空。若要以未设置密码的root用户登录本机的MySQL数据库,可以执行以下命令:
[root@RedHat6-1 ~]# mysql -u root //"-u"选项用于指定认证用户
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.5.24-log Source distribution
Copyright (c) 2000, 2011, 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>
有密码的情况下,还应使用“-p” 选项来进行密码校验。
[root@RedHat6-1 ~]# mysql -u root -p
Enter password: //根据提示输入正确的密码
2.执行MySQL操作语句
验证成功以后将进入提示符为“mysql>”的数据库操作环境,用户可以输入各种操作语句对数据库进行管理。每一条MySQL操作语句以分号“;”结束,输入时可以不区分大小写,但习惯上将MySQL语句中的关键部分大写。
(1)查看当前服务器中有哪些库
mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| #mysql50#.gnome2 |
| #mysql50#.mozilla |
| bbs |
| mysql |
| performance_schema |
| test |
+--------------------+
7 rows in set (0.01 sec)
(2) 查看当前使用的库中有那些表
先使用USE语句切换到所使用的库,再用SHOW TABLES语句用于查看当前所在的库中包含的表。
mysql> USE mysql;
Database changed
mysql> SHOW TABLES;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| event |
| func |
| general_log |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| host |
| ndb_binlog_index |
| plugin |
| proc |
| procs_priv |
| proxies_priv |
| servers |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
24 rows in set (0.01 sec)
3.退出"mysql>"操作环境
在"mysql>"环境中,执行“exit”或“quit”命令可以退出,返回到原来的Shell环境。
mysql> exit
Bye
案例新版本(mysql-5.7.17.tar.gz)
环境 CentOS7 系统
官方站点为 https://dev.mysql.com/
•MySQL的编译安装
1. 准备工作如上,新老版本一样。
2. 源码编译安装
新版本5.7需要Boost这个库,所以需要下载安装,这里下载1_59_0版本,注意这个版本和MySQL的版本是相对应的。
(1) 将下载的mysql源码包解压到/opt目录下,boost源码包解压到/usr/local/目录下。
tar zxvf mysql-5.5.24.tar.gz -C /opt/
tar zxvf boost_1_59_0.tar.gz -C /usr/local/
mv /usr/local/boost_1_59_0 boost #重命名解压后的boost库
(2)切换到展开的源码目录mysql-mysql-5.7.17,进行配置,cmake编译。