这篇文章将为大家详细讲解有关MYSQL如何搭建,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。mysql安装可以分为 1.rpm方式,2.tar压缩包方式,两者的差别rpm类似“一键安装”模式,tar方式则是”高级定义“,企业中大多数为“高级定义”方式安装。rpm方式安装一:前提准备1.检测是否已经安装rpm -qa | grep mysql2.检测是否有mysql服务ps -ef | grep mysql3.检测是否可连接外网ping www.baidu.com4. 配置yum源自带的yum源可以满足需要,如不满足需自行配置二:安装步骤1.搜索到源,如果报错可能是网络不通。yum search mysql2.在线安装yum install -y mysql-server.x86_64 –服务端yum install -y mysql.x86_64 –客户端三:启动服务1.service mysqld start (备注: mysqld ‘D’表示后台运行的进程)2.查看服务,端口号:ps -ef | grep mysqlnetstat -nls | grep 3306备注:查看到3306默认端口号即mysql服务启动四: 进入用户安装好后悔默认创建root用户,密码为空[root@hadoop001 ~]# mysql -uroot -pEnter password: 直接回车 -备注:生成采用交互式输密码,防止明文history命令将密码明文。tar方式安装mysql包企业里专门的软件会有专门的用户去部署、运行oa系统 oaadminerp系统 erpadmin规范用户可以规范权限,易于管理mysql 一个关系型数据库被oracle收购,有免费版有收费版。oraclepostgresqlsqlserverid name age1 ruoze 182 20二:tar方式安装1.在联网情况下可以网络直接下载安装包[root@sht-sgmhadoopnn-01 ~]# cd /usr/local[root@sht-sgmhadoopnn-01 local]# wget https://downloads.mariadb.com/archives/mysql-5.6/mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz[root@sht-sgmhadoopnn-01 local]# wget https://downloads.mariadb.com/archives/mysql-5.6/mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz.md5–这里我们用专用包下载mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz2.本次安装采用现成的安装包进行安装secureCRT中输入rz命令1. root用户进入目录[root@sht-sgmhadoopnn-01 ~]#
cd /usr/local2.用md5检测包的完整性。[root@sht-sgmhadoopnn-01 local]# cat mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz.md5 –原始包中自带的md5值61affe944eff55fcf51b31e67f25dc10 mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz[root@sht-sgmhadoopnn-01 local]# md5sum mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz61affe944eff55fcf51b31e67f25dc10 mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz2. 检测是否已经安装[root@sht-sgmhadoopnn-01 local]# ps -ef|grep mysqldroot 2493 2423 0 19:48 pts/3 00:00:00 grep mysqld[root@sht-sgmhadoopnn-01 local]# rpm -qa |grep -i mysql3.解压包到指定目录,然后重命名[root@sht-sgmhadoopnn-01 local] cd /usr/local[root@sht-sgmhadoopnn-01 local] tar xzvf mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz –路径是root用户下/usr/local[root@sht-sgmhadoopnn-01 local]# mv mysql-5.6.23-linux-glibc2.5-x86_64 mysql –将解压后的包重命名为mysql(因为之后的mysqladmin用户家目录是 /usr/loca/mysql,这样在su – mysqladmin切换到家目录后,直接进入解压后的包目录,便于安装.)4.创建用户组[root@sht-sgmhadoopnn-01 local]# groupadd -g 101 dba[root@sht-sgmhadoopnn-01 local]# useradd -u 514 -g dba -G root -d /usr/local/mysql mysqladminuseradd: warning: the home directory already exists. –如果用户存在要当心了Not copying any file from skel directory into it. –由于用户已经存在会导致环境变量不会在家目录中存在,坑!## if user mysqladmin is existing,please execute the following command of usermod.##[root@sht-sgmhadoopnn-01 local]# usermod -u 514 -g dba -G root -d /usr/local/mysql[root@sht-sgmhadoopnn-01 local]# userdel mysqladmin –如用户已存在则删除5.为用户创建密码[root@sht-sgmhadoopnn-01 local]# id mysqladminuid=514(mysqladmin) gid=101(dba) groups=101(dba),0(root)[root@sht-sgmhadoopnn-01 local]# passwd mysqladmin6.拷贝环境变量.bash_profile等,如果ls -lart有,此步骤可以省略## copy 环境变量配置文件至mysqladmin用户的home目录中,为了以下步骤配置个人环境变量[root@sht-sgmhadoopnn-01 local]# cp /etc/skel/.* /usr/local/mysql –将环境变量拷贝到mysqladmin家目录下cp: omitting directory `/etc/skel/.’cp: omitting directory `/etc/skel/..’cp: omitting directory `/etc/skel/.mozilla’6.1配置环境变量[mysqladmin@sht-sgmhadoopnn-01 ~]$ cat .bash_profile# .bash_profile# Get the aliases and functionsif [ -f ~/.bashrc ]; then. ~/.bashrcfi# User specific environment and startup programsexport MYSQL_HOME=/usr/local/mysqlexport PATH=${MYSQL_HOME}/bin:$PATHexport PATHps1=`uname -n`”:”$USER”:”$PWD”:>”; –注意变量名要大写export PS1#‘:’是分隔符,每次加环境变量要放到$PATH的前面(新变量放在前面是因为linux命令执行是按$PATH的先后顺序查找的,如果$PATH中已经包含老版本的变量值,优先寻找的还是老版本的环境变量),$PATH的意思原先的环境变量+新的变量使变量生效. .bash_profilesu – mysqladmin拷贝环境变量后exit用户重新进入su – mysqladmin 可以看到当前光标处用户路径已经带出来7.配置mysql主配置文件my.cnf (640权限)寻找配置文件的顺序#defualt start: /etc/my.cnf->/etc/mysql/my.cnf->SYSCONFDIR/my.cnf->$MYSQL_HOME/my.cnf-> –defaults-extra-file->~/my.cnf统一的我们在第一个位置配文件[root@sht-sgmhadoopnn-01 mysql]# cd /etc/ –在etc目录下建立my.cnf[root@sht-sgmhadoopnn-01 etc]# touch my.cnf配置文件内容:[root@sht-sgmhadoopnn-01 etc]# vi my.cnf[client] #客户端配置位置port = 3306socket = /usr/local/mysql/data/mysql.sock[mysqld] #服务端配置位置port = 3306socket = /usr/local/mysql/data/mysql.sockskip-external-lockingkey_buffer_size = 256Msort_buffer_size = 2Mread_buffer_size = 2Mread_rnd_buffer_size = 4Mquery_cache_size= 32Mmax_allowed_packet = 16Mmyisam_sort_buffer_size=128Mtmp_table_size=32Mtable_open_cache = 512thread_cache_size = 8wait_timeout = 86400interactive_timeout = 86400max_connections = 600# Try number of CPU’s*2 for thread_concurrencythread_concurrency = 32#isolation level and default enginedefault-storage-engine = INNODBtransaction-isolation = READ-COMMITTEDserver-id = 1basedir = /usr/local/mysqldatadir = /usr/local/mysql/datapid-file = /usr/local/mysql/data/hostname.pid#open performance schemalog-warningssysdate-is-nowbinlog_format = MIXEDlog_bin_trust_function_creators=1log-error = /usr/local/mysql/data/hostname.errlog-bin=/usr/local/mysql/arch/mysql-bin#other logs#general_log =1#general_log_file = /usr/local/mysql/data/general_log.err#slow_query_log=1#slow_query_log_file=/usr/local/mysql/data/slow_log.err#for replication slave#log-slave-updates#sync_binlog = 1#for innodb optionsinnodb_data_home_dir = /usr/local/mysql/data/ #存放数据目录innodb_data_file_path = ibdata1:500M:autoextendinnodb_log_group_home_dir = /usr/local/mysql/archinnodb_log_files_in_group = 2innodb_log_file_size = 200M#生产上 机械硬盘#sata盘 5000r 7200r(大众生产) 10000r(大众生产) 15000r 有条件用ssd# innodb_buffer_pool_size 生产调优调大 8Ginnodb_buffer_pool_size = 1024M #free命令查看服务器内存,再适度分配innodb_additional_mem_pool_size = 50Minnodb_log_buffer_size = 16Minnodb_lock_wait_timeout = 100#innodb_thread_concurrency = 0innodb_flush_log_at_trx_commit = 1innodb_locks_unsafe_for_binlog=1#innodb io features: add for mysql5.5.8performance_schemainnodb_read_io_threads=4innodb-write-io-threads=4innodb-io-capacity=200#purge threads change default(0) to 1 for purgeinnodb_purge_threads=1innodb_use_native_aio=on#case-sensitive file names and separate tablespaceinnodb_file_per_table = 1lower_case_table_names=1[mysqldump]quickmax_allowed_packet = 16M #最大数据包[mysql]no-auto-rehash[mysqlhotcopy]interactive-timeout[myisamchk]key_buffer_size = 256Msort_buffer_size = 256Mread_buffer = 2Mwrite_buffer = 2M—————————8.更改my.cnf权限[root@sht-sgmhadoopnn-01 local]# chown mysqladmin:dba /etc/my.cnf[root@sht-sgmhadoopnn-01 local]# chmod
640
/etc/my.cnf[root@sht-sgmhadoopnn-01 etc]# ll my.cnf-rw-r—– 1
mysqladmin dba
2201 Aug 25 23:09 my.cnf9.更改家目录下用户、组的权限[root@sht-sgmhadoopnn-01 local]# chown -R mysqladmin:dba /usr/local/mysql[root@sht-sgmhadoopnn-01 local]# chmod -R 755 /usr/local/mysql10. 切换到mysql家目录,并创建arch目录,arch目录是在my.cnf指定的root@sht-sgmhadoopnn-01 local]# su – mysqladmin[mysqladmin@sht-sgmhadoopnn-01 ~]$ pwd/usr/local/mysql创建arch目录用来存储binlog二进制归档日志 mysql–maxwell–kafka–sparkstrm–hbase 实时cd /usr/local/mysqlmkdir arch11.开始安装,用家目录下的脚本[mysqladmin@sht-sgmhadoopnn-01 ~]$ scripts/mysql_install_dbInstalling MySQL system tables…./bin/mysqld:error while loading shared libraries: libaio.so.1: cannot open shared object file:No such file or directory #缺少libaio.so 包====================缺少包解决方法:1.查看版本[root@sht-sgmhadoopnn-01 local]# cat /proc/versionLinux version 2.6.18-164.11.1.el5 (mockbuild@builder10.centos.org) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-46)) #1 SMP Wed Jan 20 07:32:21 EST 20102.查看是否有gcc包[root@sht-sgmhadoopnn-01 local]# rpm -qa |grep gcclibgcc-4.1.2-46.el5_4.2libgcc-4.1.2-46.el5_4.23.安装对应包[root@sht-sgmhadoopnn-01 local]# yum -y install libaio假设前面安装错误再次安装,需要清空两个目录遗留文件:rm -rf data/*rm -rf arch/*=====================12.开始安装,为保险起见,指定了执行路径,实在是不用指定的。[mysqladmin@sht-sgmhadoopnn-01 ~]$ scripts/mysql_install_db –user=mysqladmin –basedir=/usr/local/mysql –datadir=/usr/local/mysql/data查看data/hostname.err文件 仔细错误或者:scripts/mysql_install_db –user=mysqladmin –basedir=/usr/local/mysql –datadir=/usr/local/mysql/data –defaults-file=/etc/my.cnf –手工指定defaults-file方法或者:[root@bogon scripts]# /usr/local/mysql/scripts/mysql_install_db –user=mysqladmin –basedir=/usr/local/mysql –datadir=/usr/local/mysql/data &备注:因为mysql家目录为/usr/local/mysql,而我们上面步骤已经将tar包更名为mysql,在su – mysqladmin切换到家目录时,已经进入tar解压后的安装包,此时可以看到script目录13.配置mysql开机自启[root@sht-sgmhadoopnn-01 ~]# cd /usr/local/mysql#将服务文件拷贝到init.d下,并重命名为mysql[root@sht-sgmhadoopnn-01 mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysql#赋予可执行权限[roo免费主机域名t@sht-sgmhadoopnn-01 mysql]# chmod +x /etc/rc.d/init.d/mysql#删除服务[root@sht-sgmhadoopnn-01 mysql]# chkconfig –del mysql#重新添加服务[root@sht-sgmhadoopnn-01 mysql]# chkconfig –add mysql#添加开机启动服务[root@sht-sgmhadoopnn-01 mysql]# chkconfig –level 345 mysql on[root@sht-sgmhadoopnn-01 mysql]# vi /etc/rc.local#!/bin/sh## This script will be executed *after* all the other init scripts.# You can put your own initialization stuff in here if you don’t# want to do the full Sys V style init stuff.touch /var/lock/subsys/localsu – mysqladmin -c “/etc/init.d/mysql start –federated”—————[root@hadoop ~]# cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysql[root@hadoop ~]# chmod +x /etc/rc.drc.d/ rc.local rc.sysinit[root@hadoop ~]# chmod +x /etc/rc.d/init.d/mysql[root@hadoop ~]# ll /etc/rc.d/init.d/mysql-rwxr-xr-x 1 root root 10880 Jan 29 12:47 /etc/rc.d/init.d/mysql—————9. 启动mysql[root@sht-sgmhadoopnn-01 mysql]# su – mysqladmin[mysqladmin@sht-sgmhadoopnn-01 ~]$ pwd/usr/local/mysql[mysqladmin@sht-sgmhadoopnn-01 ~]$ rm -rf my.cnf #保留也可以,因为目录下已经有了[mysqladmin@hadoop001 ~]$ service mysql start #开启服务Starting MySQL. [ OK ][mysqladmin@hadoop001 ~]$ service mysql statusMySQL running (3625) [ OK ]或者:#另一种安全模式启动,同样是可以的[mysqladmin@sht-sgmhadoopnn-01 ~]$ mysqld_safe & #安全模式开启,另一种开启方式,执行后光标处回车[1] 11802[mysqladmin@sht-sgmhadoopnn-01 ~]$ 免费主机域名150825 22:53:38 mysqld_safe Logging to ‘/usr/local/mysql/data/hostname.err’.150825 22:53:38 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data/150825 22:53:39 mysqld_safe mysqld from pid file /usr/local/mysql/data/hostname.pid ended[mysqladmin@sht-sgmhadoopnn-01 ~]$ which mysqld_safe~/bin/mysqld_safe #可以看到mysqld_safe的目录10. 查看服务监听[mysqladmin@sht-sgmhadoopnn-01 ~]$ ps -ef|grep
mysqld –是mysqld不是mysql514 6247 6219 0 17:30 pts/1 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe514 6902 6247 2 17:30 pts/1 00:00:01 /usr/local/mysql/bin/mysqld –basedir=/usr/local/mysql –datadir=/usr/local/mysql/data –plugin-dir=/usr/local/mysql/lib/plugin –log-error=/usr/local/mysql/data/hostname.err –pid-file=/usr/local/mysql/data/hostname.pid –socket=/usr/local/mysql/data/mysql.sock –port=3306 #3306说明已经启动514 6927 6219 0 17:31 pts/1 00:00:00 grep mysqld查看监听[mysqladmin@sht-sgmhadoopnn-01 ~]$ netstat -tulnp | grep mysql #查看端口(Not all processes could be identified, non-owned process infowill not be shown, you would have to be root to see it all.)tcp 0 0 :::3306 :::* LISTEN 11541/mysqld[root@sht-sgmhadoopnn-01 local]# service mysql statusMySQL running (21507) [ OK ]至此部署完成备注:mysql会创建两个用户1.root用户 密码为空
要更改密码2.空用户 密码为空 要删除该用户登录方式:#注意事项1.不用明密码登录。2.-p等参数不能加空格bin/mysql -uroot -p -h227.0.0.1 #回车输入密码 此方式安全不会被history记录bin/mysql -uroot -p123456 -h227.0.0.1 #此方式不安全的 会被history记录bin/mysql -u root -p 123456 -h 127.0.0.1 -P3306 #加端口号方式,此方式不安全,127.0.0.1是自己的电脑ip11. 登录mysql[mysqladmin@sht-sgmhadoopnn-01 ~]$ bin/mysql -uroot -p也可以进入/usr/local/mysql/bin目录,./mysql -uroot -p表示执行当前路径下的mysql ./是相对路径 。mysql> show databases;+——————–+| Database |+——————–+| information_schema || mysql || performance_schema || test |+——————–+4 rows in set (0.00 sec)12.更改root密码,删除空用户mysql> use mysqlDatabase changed安全起见要做两件事1.更改root的密码不为空2.删除空用户mysql> update user set password=password(‘123456′) where user=’root’; #将root用户更改密码,passwodr(‘123456’)是加密Query OK, 4 rows affected (0.00 sec)Rows matched: 4 Changed: 4 Warnings: 0mysql> select host,user,password from user;+—————-+——+——————————————-+| host | user | password |+—————-+——+——————————————-+| localhost | root | *6340BE3C15D246B0D74BAF3F135915ED19E0069F || sht-sgmhadoopnn-01 | root | *6340BE3C15D246B0D74BAF3F135915ED19E0069F || 127.0.0.1 | root | *6340BE3C15D246B0D74BAF3F135915ED19E0069F || ::1 | root | *6340BE3C15D246B0D74BAF3F135915ED19E0069F || localhost | | || sht-sgmhadoopnn-01 | | |+—————-+——+——————————————-+6 rows in set (0.00 sec)mysql> delete from user where user=”; #删除空用户mysql> select host,user,password from user;+—————-+——+——————————————-+| host | user | password |+—————-+——+——————————————-+| localhost | root | *6340BE3C15D246B0D74BAF3F135915ED19E0069F || sht-sgmhadoopnn-01 | root | *6340BE3C15D246B0D74BAF3F135915ED19E0069F || 127.0.0.1 | root | *6340BE3C15D246B0D74BAF3F135915ED19E0069F || ::1 | root | *6340BE3C15D246B0D74BAF3F135915ED19E0069F |+—————-+——+——————————————-+4 rows in set (0.00 sec)#针对用户 权限的操作语句最后一步执行刷新权限mysql> flush privileges;13.重新登录bin/mysql -uroot -p -hlocalhost14.Configure .bash_profile #配置环境变量[mysqladmin@sht-sgmhadoopnn-01 ~]$ cat .bash_profile# .bash_profile# Get the aliases and functionsif [ -f ~/.bashrc ]; then. ~/.bashrcfi# User specific environment and startup programsexport MYSQL_HOME=/usr/local/mysqlexport PATH=${MYSQL_HOME}/bin:$PATHexport PATHps1=`uname -n`”:”$USER”:”$PWD”:>”; –注意变量名要大写export PS1#‘:’是分隔符,每次加环境变量要放到$PATH的前面(新变量放在前面是因为linux命令执行是按$PATH的先后顺序查找的,如果$PATH中已经包含老版本的变量值,优先寻找的还是老版本的环境变量),$PATH的意思原先的环境变量+新的变量使变量生效. .bash_profilesu – mysqladmin关于“MYSQL如何搭建”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。
这篇文章主要讲解了“怎么使用gps校时母钟”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“怎么使用gps校时母钟”吧!gps校时母钟采用的是先进的多模卫星接收机,授时信号容易接收:覆盖范围大,没有通讯盲区,采用G…