mysql 安装

来源:互联网 发布:人民银行金融数据 编辑:程序博客网 时间:2024/06/08 11:21
学生信息:t1:学号 姓名 性别 年龄 家庭住址 籍贯...t2:学号 专业 选课 教师 ...关系型数据库(RDBMS):oracle mysql db2 sql server sybase...优点:容易理解、方便使用、数据一致、读写实时数据一致:事务1、ATM,输入密码2、连接数据库,验证密码3、验证成功后,获取用户信息4、转账 5005、你的账户扣除500;同时在对方的账户里增加5006、取卡走人要么全部成功;要么全部失败;在我们数据库中一个事务是由很多条sql语句组成,要么全部执行成功,要么全部失败;这样才能保证数据的一致性应用场景:1、对数据的一致性要求比较高(银行的交易系统)2、对数据的实时性要求较高非关系型数据:【nosql】 Mongdb redis memcahe ..https://db-engines.com/en/rankingMysql数据库的安装:1、通过二进制包的方式安装rpm:xxx.el6.x86_64.rpmglibc: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 startInitializing MySQL database:  Installing MySQL system tables...OKFilling help tables...OK   以上2个ok说明数据库初始化完毕To start mysqld at boot time you have to copysupport-files/mysql.server to the right place for your systemPLEASE 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_installationwhich will also give you the option of removing the testdatabases and anonymous user created by default.  This isstrongly 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.plcd /usr/mysql-test ; perl mysql-test-run.plPlease 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 currentpassword for the root user.  If you've just installed MySQL, andyou 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 MySQLroot 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 anyoneto log into MySQL without having to have a user account created forthem.  This is intended only for testing, and to make the installationgo a bit smoother.  You should remove them before moving into aproduction environment.Remove anonymous users? [Y/n] n ... skipping.Normally, root should only be allowed to connect from 'localhost'.  Thisensures 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 canaccess.  This is also intended only for testing, and should be removedbefore 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 farwill 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 MySQLinstallation should now be secure.Thanks for using MySQL!# netstat -nltp|grep 3306tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      4739/mysqld# mysql -p123mysql> 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' -pEnter 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: 0mysql> 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/mysqlsocket=/var/lib/mysql/mysql.sockuser=mysql# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0[mysqld_safe]log-error=/var/log/mysqld.logpid-file=/var/run/mysqld/mysqld.pid2> 直接以后台安全进程启动mysql# /usr/bin/mysqld_safe --skip-grant-tables &2、安装mysql AB 官方的rpm包MySQL-server-5.6.19-1.el6.x86_64.rpmMySQL-client-5.6.19-1.el6.x86_64.rpm      MySQL-shared-5.6.19-1.el6.x86_64.rpmMySQL-devel-5.6.19-1.el6.x86_64.rpm       MySQL-shared-compat-5.6.19-1.el6.x86_64.rpmMySQL-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 statementmysql> 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 123Enter password: ERROR 1049 (42000): Unknown database '123'# mysql -uroot -e 'show databases;' -pEnter password: +--------------------+| Database           |+--------------------+| information_schema || mysql              || performance_schema |+--------------------+作业:1、安装glibc的mysql;一台主机同时启动多个实例2、预习源码安装mysql (参照mysql的官方文档)
原创粉丝点击