标签:基础 code tst 支持 一致性 rom serve start 数据信息
MySQL数据库基础[root@localhost ~] yum install gcc gcc-c++ cmake ncurses ncurses-devel bison -y
[root@localhost mysql-5.7.17] useradd -s /sbin/nologin mysql
[root@localhost ~] tar zxvf mysql-5.7.17.tar.gz -C /opt/
[root@localhost ~] tar zxvf boost_1_59_0.tar.gz -C /usr/local/ #boost包是C语言里面的函数库
[root@localhost ~] mv /usr/local/boost_1_59_0 /usr/local/boost
[root@localhost mysql-5.7.17] cmake \
> -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ #指定安装路径
> -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \ #通讯连接文件
> -DSYSCONFDIR=/etc \ #MySQL配置文件目录
> -DSYSTEMD_PID_DIR=/usr/local/mysql \ #PID进程文件
> -DDEFAULT_CHARSET=utf8 \ #字符级
> -DDEFAULT_COLLATION=utf8_general_ci \ #
> -DWITH_INNOBASE_STORAGE_ENGINE=1 \ #下面四个是存储引擎
> -DWITH_ARCHIVE_STORAGE_ENGINE=1 \
> -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
> -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
> -DMYSQL_DATADIR=/usr/local/mysql/data \ #数据库文件
> -DWITH_BOOST=/usr/local/boost \ #支持函授库
> -DWITH_SYSTEMD=1 #生成一个便于systemctl管理的文件
[root@localhost mysql-5.7.17] make && make install #这个过程比较长需耐心等待
[root@localhost mysql-5.7.17] chown -R mysql.mysql /usr/local/mysql/
[root@localhost mysql-5.7.17] vim /etc/my/cnf
#在开头插入
[client ] #客户端区域
port = 3306 #端口号3306
default-character-set=utf8 #字符集
socket = /usr/local/mysql/mysql.sock
[mysql]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock #连接文件
[mysqld]
user = mysql #管理用户是mysql
basedir = /usr/local/mysql #工作目录位置
datadir = /usr/local/mysql/data #数据库文件目录
port = 3306
character_set_server=utf8
pid-file = /usr/local/mysql/mysqld.pid #进程号
socket = /usr/local/mysql/mysql.sock #
server-id = 1 #sererID
#删除原有文件的mysqld及下列九行添加上面的mysqld
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES #添加sql模式支持各种模式
[root@localhost ~] ls -l | grep /etc/my.cnf
-rw-r--r--. 1 root root 728 6月 25 15:43 my.cnf
[root@localhost ~] chown mysql:mysql /etc/my.cnf
-rw-r--r--. 1 mysql mysql 728 6月 25 15:43 my.cnf
[root@localhost ~] echo ‘PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH‘ >> /etc/profile
[root@localhost ~] echo ‘export PATH‘ >> /etc/profile
[root@localhost ~] source /etc/profile
[root@localhost ~] cd /usr/local/mysql/
[root@localhost mysql] bin/mysqld --initialize-insecure \ #生成一个初始化密码这个初始化密码是空的等会我会修改密码
--user=mysql \ #指定管理用户啊
--basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
[root@localhost ~] cd /usr/lib/systemd/system
[root@localhost system] ls
mysqld.service #这是便于系统管理的摸板 mysqld@.service
[root@localhost system] cp mysqld.service /usr/lib/systemd/system/ # 复制到此目录下
[root@localhost ~] systemctl daemon-reload #刷新让系统识别
[root@localhost ~] systemctl start mysqld #开启数据库
[root@localhost ~] netstat -anpt | grep 3306 #查看端口号
tcp6 0 0 :::3306 :::* LISTEN 77165/mysqld
[root@localhost ~] systemctl stop firewalld.service #关闭防火墙
[root@localhost ~] setenforce 0
[root@localhost ~] mysqladmin -u root -p password "abc123" #修改初始化密码
[root@localhost ~] mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.7.17 Source distribution
Copyright (c) 2000, 2016, 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> show databases; #查看数据库能显示下列数据库信息就已经安装完成
+-----------------------------+
| Database |
+-----------------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+-----------------------------+
6 rows in set (0.00 sec)
序列号 | 姓名 | 成绩 | 爱好 |
---|---|---|---|
1 | zhangsan | 78 | 看书 |
2 | lisi | 89.5 | 玩游戏 |
3 | wangwu | 93.5 | 玩游戏 |
1:先创建数据库名字为“五年级二班”
mysql> create database 五年级二班; #创建数据库
Query OK, 1 row affected (0.00 sec)
mysql> show databases;
+------------------------------+
| Database |
+------------------------------+
| information_schema |
| 五年级二班 |
| mysql |
| performance_schema |
| sys |
+-------------------------------+
5 rows in set (0.00 sec)
mysql> use 五年级二班; #进入数据库
Database changed
mysql> create table 班级信息(序列号 varchar(10),姓名 varchar(10),成绩 decimal(5,2),爱 好 varchar(10)); #创建表
Query OK, 0 rows affected (0.01 sec)
mysql> desc 班级信息;
+-----------+--------------+--------+--------+--------+----------+
| Field | Type | Null | Key | Default | Extra |
+-----------+--------------+--------+--------+--------+-----------+
| 序列号 | varchar(10) | YES | | NULL | |
| 姓名 | varchar(10) | YES | | NULL | |
| 成绩 | decimal(5,2) | YES | | NULL | |
| 爱好 | varchar(10) | YES | | NULL | |
+-----------+--------------+-------+--------+---------+-----------+
4 rows in set (0.00 sec)
mysql> insert into 班级信息 (序列号,姓名,成绩,爱好) values (‘1‘,‘zhangsan‘,‘78‘,‘看书‘); #编辑表中信息
Query OK, 1 row affected (0.01 sec)
mysql> insert into 班级信息 (序列号,姓名,成绩,爱好) values (‘2‘,‘lisi‘,‘89.5‘,‘玩游戏‘));
Query OK, 1 row affected (0.00 sec)
mysql> insert into 班级信息 (序列号,姓名,成绩,爱好) values (‘2‘,‘lisi‘,‘93.5‘,‘玩游戏‘));
Query OK, 1 row affected (0.00 sec)
mysql> select * from 班级信息; #查看所有来自班级信息的数据
+-----------+--------------+----------+-----------+
| 序列号 | 姓名 | 成绩 | 爱好 |
+-----------+--------------+----------+-----------+
| 1 | zhangsan | 78.00 | 看书 |
| 2 | lisi | 89.50 | 玩游戏 |
| 3 | wangwu | 93.50 | 玩游戏 |
+-----------+--------------+--------+-----------+
3 rows in set (0.00 sec)
标签:基础 code tst 支持 一致性 rom serve start 数据信息
原文地址:http://blog.51cto.com/13645280/2132869