Mysql安装和配置
注意 :在安装时候要注意命令是在哪个用户,哪个目录下面执行的
1.上传压缩包
上传压缩包到/usr/local tar-zxvf mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz 解压
2.检查以前是否有安装
1 2 3 ps -ef |grep mysqld rpm -qa |grep -i mysql
3.建立软连接
1 2 cd /usr/local ln -s mysql-5.6.23-linux-glibc2.5-x86_64 mysql
4.创建用户和用户组
root用户 cd /usr/local
1 2 3 4 5 groupadd -g 101 dba useradd -u 514 -g dba -G root -d /usr/local /mysql mysqladmin [root@localhost local ] uid=514(mysqladmin) gid=101(dba) groups=101(dba),0(root)
设置密码
设置mysqladmin的用户主组和家目录
1 2 3 usermod -u 514 -g dba -G root -d /usr/local /mysql mysqladmin cp /etc/skel/.* /usr/local /mysql ==> 解决样式缺失问题
5.创建 /etc/my.cnf文件权限640
cd /etc/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 vi my.cnf ****** [client] port = 3306 socket = /usr/local /mysql/data/mysql.sock [mysqld] port = 3306 socket = /usr/local /mysql/data/mysql.sock skip-external-locking key_buffer_size = 256M sort_buffer_size = 2M read_buffer_size = 2M read_rnd_buffer_size = 4M query_cache_size= 32M max_allowed_packet = 16M myisam_sort_buffer_size=128M tmp_table_size=32M table_open_cache = 512 thread_cache_size = 8 wait_timeout = 86400 interactive_timeout = 86400 max_connections = 600 thread_concurrency = 32 default-storage-engine = INNODB transaction-isolation = READ-COMMITTED server-id = 1 basedir = /usr/local /mysql datadir = /usr/local /mysql/data pid-file = /usr/local /mysql/data/hostname.pid log -warningssysdate-is-now binlog_format = MIXED log_bin_trust_function_creators=1 log -error = /usr/local /mysql/data/hostname.errlog -bin=/usr/local /mysql/arch/mysql-bininnodb_data_home_dir = /usr/local /mysql/data/ innodb_data_file_path = ibdata1:500M:autoextend innodb_log_group_home_dir = /usr/local /mysql/arch innodb_log_files_in_group = 2 innodb_log_file_size = 200M innodb_buffer_pool_size = 2048M innodb_additional_mem_pool_size = 50M innodb_log_buffer_size = 16M innodb_lock_wait_timeout = 100 innodb_flush_log_at_trx_commit = 1 innodb_locks_unsafe_for_binlog=1 performance_schema innodb_read_io_threads=4 innodb-write-io-threads=4 innodb-io-capacity=200 innodb_purge_threads=1 innodb_use_native_aio=on innodb_file_per_table = 1 lower_case_table_names=1 [mysqldump] quick max_allowed_packet = 16M [mysql] no-auto-rehash [mysqlhotcopy] interactive-timeout [myisamchk] key_buffer_size = 256M sort_buffer_size = 256M read_buffer = 2M write_buffer = 2M
6.更改权限和安装所需依赖包
1 2 3 yum install -y perl yum install -y autoconf yum install -y libaio
cd /usr/local
1 2 chown mysqladmin:dba /etc/my.cnf chmod 640 /etc/my.cnf
1 2 3 [root@localhost local ] [root@localhost etc] -rw-r----- 1 mysqladmin dba 2268 Dec 1 14:08 my.cnf
1 2 3 4 5 6 7 8 9 权限修正时候最好加上/* chown -R mysqladmin:dba /usr/local /mysql chown -R mysqladmin:dba /usr/local /mysql/* chown -R mysqladmin:dba /usr/local /mysql-5.6.23-linux-glibc2.5-x86_64 mysql5.6 在部署的时候就是一个空密码 chmod -R 755 /usr/local /mysql chmod -R 755 /usr/local /mysql/* chmod -R 755 /usr/local /mysql-5.6.23-linux-glibc2.5-x86_64
7.切换用户执行安装程序
1 2 3 su - mysqladmin mkdir arch backup scripts/mysql_install_db --user=mysqladmin --basedir=/usr/local /mysql --datadir=/usr/local /mysql/data
8.配置myql服务设置开机自启动
1 2 3 4 5 6 7 8 9 10 11 12 cd /user/local /mysql[root@localhost mysql] [root@localhost mysql] [root@localhost mysql] [root@localhost mysql] [root@localhost mysql] [root@localhost mysql] 添加:su - mysqladmin -c "/etc/init.d/mysql start --federated" 当切换到mysqladmin用户的时候自动开启mysql服务
9.启动mysql服务
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 su - mysqladmin rm -rf my.cnf 执行 mysqld_safe & 查看mysqld进程 [root@localhost etc] mysqlad+ 10427 1 0 14:20 pts/0 00:00:00 /bin/sh /usr/local /mysql/bin/mysqld_safe mysqlad+ 11070 10427 0 14:20 pts/0 00:00:02 /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 root 13384 9841 0 15:15 pts/0 00:00:00 grep --color=auto mysqld [root@localhost ~] tcp6 0 0 :::3306 :::* LISTEN 11070/mysqld [root@localhost ~] SUCCESS! MySQL running (11070)
10登录mysql
su - mysqladmin
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 输入mysql 进入mysql客户端 mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | +--------------------+ 显示四个说明正常 mysql> use mysql 设置密码 mysql> update user set password=password('123456' ) where user='root' ; mysql> select host,user,password from user; +----------------+------+-------------------------------------------+ | host | user | password | +----------------+------+-------------------------------------------+ | localhost | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | | localhost | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | | 127.0.0.1 | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | | ::1 | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | | localhost | | | +----------------+------+-------------------------------------------+ mysql> delete from user where user='' ; 授权远程访问 grant all privileges on *.* to root@'%' identified by '123456' ; flush privileges grant all privileges on *.* to root@'%' identified by 'ruozedata' 授予所有的权限,给所有的用户下面的所有对象给root用户,@是允许这台机器来自于哪些用户,百分号代表任意的意思, % 任意ip访问 mysql> use mysql Database changed mysql> select host,user,password from user; +-----------------------+------+-------------------------------------------+ | host | user | password | +-----------------------+------+-------------------------------------------+ | localhost | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | | localhost.localdomain | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | | 127.0.0.1 | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | | ::1 | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | | % | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | +-----------------------+------+-------------------------------------------+
11.编辑配置文件.bashrc
添加mysql_home
1 [mysqladmin@localhost ~]$ cat .bashrc
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 if [ -f /etc/bashrc ]; then . /etc/bashrc fi export MYSQL_HOME=/usr/local /mysqlexport PATH=$MYSQL_HOME /bin:$PATH PS1=`uname -n`":" '$USER' ":" '$PWD' ":>" ; export PS1 alias l="ls -ltr" alias la="ls -la" alias d="df -lk" alias bg ="ps -aef|grep mysql" alias base="cd /usr/local/mysql" alias bin="cd //usr/local/mysql/bin" alias dba="cd /usr/local/mysql/dba" alias sh="cd /usr/local/mysql/dba/sh" alias sql="cd /usr/local/mysql/dba/sql" alias config="cd /usr/local/mysql/dba/config" alias dbalog="cd /usr/local/mysql/dba/log" alias arch="cd /usr/local/mysql/arch" alias data="cd /usr/local/mysql/data"
[mysqladmin@localhost ~]$ source .bashrc
12.检查配置是否正确
1 2 3 4 [mysqladmin@localhost ~]$ source .bashrc [mysqladmin@localhost ~]$ echo $MYSQL_HOME /usr/local /mysql [mysqladmin@localhost ~]$ which mysql
13.配置主机名
1 2 3 4 5 6 7 8 9 10 11 cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.52.50 ruozedata001 第一行第二行 不要动 内网中配置ip hostname 代码中统一写hostName ping hostname shell脚本 程序 CDH部署 统统使用hostname
MySQL安装
彩蛋:
1.台配置执行脚本的三种方式:
1 2 3 /root/test.sh & nohup /root/test.sh & nohup /root/test.sh 2>&1 &
2.crontab秒级定时
首先配置分钟级别,然后在脚本中采用for循环加sleep控制