学生信息:
t1:学号 姓名 性别 年龄 家庭住址 籍贯...
t2:学号 专业 选课 教师 ...
关系型数据库(RDBMS):oracle mysql db2 sql server sybase...
优点:容易理解、方便使用、数据一致、读写实时
数据一致:事务
1、ATM,输入密码
2、连接数据库,验证密码
3、验证成功后,获取用户信息
4、转账 500
5、你的账户扣除500;同时在对方的账户里增加500
6、取卡走人
要么全部成功;要么全部失败;
在我们数据库中一个事务是由很多条sql语句组成,要么全部执行成功,要么全部失败;这样才能保证数据的一致性
应用场景:1、对数据的一致性要求比较高(银行的交易系统)2、对数据的实时性要求较高
非关系型数据:【nosql】 Mongdb redis memcahe ..
https://db-engines.com/en/ranking
Mysql数据库的安装:
1、通过二进制包的方式安装
rpm:xxx.el6.x86_64.rpm
glibc:Linux所有版本通用的一个二进制的软件包。也是C的运行库,几乎所有的linux系统最底层的api接口,都会依赖glibc。
优点:方便安装
缺点:不能自定义
2、源码包安装 xxx.tar.gz
三步曲 (配置编译安装)
优点:灵活,可以自定义
缺点:比较麻烦
3、构建自己的rpm包
优点:根据需求定址自己的rpm包,后续方便安装
缺点:前期的构建时间长,而且麻烦
安装:
1、使用rpm包安装
1> redhat 自己的mysqlrpm包
mysql.x86_64 5.1.71-1.el6
mysql-bench.x86_64 5.1.71-1.el6
mysql-connector-java.noarch 1:5.1.17-6.el6
mysql-connector-odbc.x86_64 5.1.5r1144-7.el6
mysql-devel.i686 5.1.71-1.el6
mysql-devel.x86_64 5.1.71-1.el6
mysql-libs.i686 5.1.71-1.el6
mysql-server.x86_64 5.1.71-1.el6
mysql-test.x86_64 5.1.71-1.el6
php-mysql.x86_64 5.3.3-26.el6
# rpm -ql mysql-server
/etc/logrotate.d/mysqld 日志轮转文件
/etc/rc.d/init.d/mysqld 启动脚本
/var/lib/mysql mysql的默认数据根目录
/var/log/mysqld.log 日志文件
/var/run/mysqld mysql进程目录
# rpm -ql mysql
/usr/bin/mysql 客户端命令
/usr/bin/mysqladmin
/usr/bin/mysqlbinlog
/usr/bin/mysqlcheck
/usr/bin/mysqldump
/usr/bin/mysqlimport
/usr/bin/mysqlshow
# /etc/rc.d/init.d/mysqld start
Initializing MySQL database: Installing MySQL system tables...
OK
Filling help tables...
OK
以上2个ok说明数据库初始化完毕
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h node1.uplook.com password 'new-password'
Alternatively you can run:
/usr/bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd /usr/mysql-test ; perl mysql-test-run.pl
Please report any problems with the /usr/bin/mysqlbug script!
[ OK ]
Starting mysqld: [ OK ]
后续配置:
# /usr/bin/mysql_secure_installation 安全配置
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
You already have a root password set, so you can safely answer 'n'.
Change the root password? [Y/n] n
... skipping.
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] n
... skipping.
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] n 生产环境中一般是不允许远程访问
... skipping.
By default, MySQL comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
# netstat -nltp|grep 3306
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 4739/mysqld
# mysql -p123
mysql> show databases 查看当前数据库
-> ;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
+--------------------+
2 rows in set (0.00 sec)
information_schema数据库:对象数据信息库,一般保存的是其他数据库的相关信息;
里面只有一个只读的表,实际上是一个视图,不是基本表,无法看到任何的相关文件
mysql数据库:核心的库
test库:测试库
后续密码设置:
1、直接使用客户端工具设置密码
# mysqladmin -u root password '123' 设置新密码
# mysqladmin -u root password 'newpass' -p123 重新设置密码
# mysqladmin -u root password 'mysql' -p
Enter password:
2、使用sql语句直接更新表信息、
mysql> update user set password=password(456) where user='root' and host='localhost';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> flush privileges; 刷新授权表
Query OK, 0 rows affected (0.00 sec)
或者
mysql> set password for 'root'@'localhost'=password('123'); 不需要刷新授权表
Query OK, 0 rows affected (0.00 sec)
3、不知道原来的密码
1> 修改配置文件
Default options are read from the following files in the given order:
/etc/mysql/my.cnf /etc/my.cnf ~/.my.cnf
如果以上配置文件有冲突,那么以最后读取到的为主
vim /etc/my.cnf
[mysqld]
skip-grant-tables 跳过授权表
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
2> 直接以后台安全进程启动mysql
# /usr/bin/mysqld_safe --skip-grant-tables &
2、安装mysql AB 官方的rpm包
MySQL-server-5.6.19-1.el6.x86_64.rpm
MySQL-client-5.6.19-1.el6.x86_64.rpm MySQL-shared-5.6.19-1.el6.x86_64.rpm
MySQL-devel-5.6.19-1.el6.x86_64.rpm MySQL-shared-compat-5.6.19-1.el6.x86_64.rpm
MySQL-embedded-5.6.19-1.el6.x86_64.rpm MySQL-test-5.6.19-1.el6.x86_64.rpm
安装前:
# rpm -e mysql-server mysql mysql-libs --nodeps
# rm -rf /var/lib/mysql/*
# cd /var/lib/mysql/
# rpm -ivh MySQL-server-5.6.19-1.el6.x86_64.rpm
# cat ~/.mysql_secret
# The random password set for the root user at Thu May 11 11:30:37 2017 (local time): FZVTUxxeTCJx3wSC 初始密码
# mysql_secure_installation
...
错误提示:找不到/var/lib/mysql/mysql.sock
解决:
# service mysql start 3306监听
注意:pid文件和sock文件是在服务启动后产生的;
错误:
mysql> show databases;
ERROR 1820 (HY000): You must SET PASSWORD before executing this statement
mysql>
mysql>
mysql>
mysql> set password for 'root'@'localhost'=password('111');
Query OK, 0 rows affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
performance_schema:数据库是mysql 5.5版本以后有的,收集操作系统性能相关的信息
mysql客户端工具:
-u:指定用户
-S:指定sock文件
-h:指定主机(ip|主机名)
-e:外部执行sql
-P:指定端口
-p:指定密码
mysql -p (默认是root用户从localhost登录)
mysql -u xxx -P xxx -p
说明:
-p参数后面跟的密码不能有空格;如果有空格就意味者访问的是参数后面的数据库
# mysql -p 123
Enter password:
ERROR 1049 (42000): Unknown database '123'
# mysql -uroot -e 'show databases;' -p
Enter password:
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
作业:
1、安装glibc的mysql;一台主机同时启动多个实例
2、预习源码安装mysql (参照mysql的官方文档)
linux下的mysql 的安装
最新推荐文章于 2021-07-30 16:14:59 发布