个人经验,直奔主题,centos7采用yum安装mysql-server 避免了各种人为的处理依赖。
1,下载官方Yum源:http://dev.mysql.com/downloads/repo/
# wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
直接将mysql*.rpm文件下载下来之后执行下列操作
sudo yum localinstall mysql57-community-release-el7-*.noarch.rpm
完成上面两步之后直接进入下一步
sudo yum install mysql-server
2,更新/etc/my.cnf或/etc/mysql/my.cnf
因为更新配置文件可能会依照特定需求修改mysql数据文件及日志文件等存储目录,为确保mysql用户对新目录拥有相应的权限,可在更新配置文件前将原mysql拥有目录复制至新目录:
[mysqld]
datadir=/home/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
skip-name-resolve
skip-grant-tables
# Disabling symbolic-links is recommended to prevent assorted security risks
#symbolic-links=0
transaction-isolation=READ-COMMITTED
# Disabling symbolic-links is recommended to prevent assorted security risks;
# to do so, uncomment this line:
# symbolic-links=0
key_buffer = 16M
key_buffer_size = 32M
max_allowed_packet = 16M
thread_stack = 256K
thread_cache_size = 64
query_cache_limit = 8M
query_cache_size = 64M
query_cache_type = 1
# Important: see Configuring the Databases and Setting max_connections
max_connections = 750
# log-bin should be on a disk with enough free space
#log-bin=/x/home/mysql/logs/binary/mysql_binary_log
# For MySQL version 5.1.8 or later. Comment out binlog_format for older versions.
#binlog_format = mixed
read_buffer_size = 2M
read_rnd_buffer_size = 16M
sort_buffer_size = 8M
join_buffer_size = 8M
# InnoDB settings
innodb_file_per_table = 1
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 64M
innodb_buffer_pool_size = 4G
innodb_thread_concurrency = 8
innodb_flush_method = O_DIRECT
innodb_log_file_size = 512M
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
2.3安装MySQL JDBC Connector
sudo yum install mysql-connector-java
2.4启动Mysql
sudo service mysqld start
2.5设置Mysql的root密码,初始密码为空(非必须)rootcentos
$ sudo /usr/bin/mysql_secure_installation
[…]
Enter current password for root (enter for none):
OK, successfully used password, moving on…
[…]
Set root password? [Y/n] y
New password:
Re-enter new password:
Remove anonymous users? [Y/n] Y
[…]
Disallow root login remotely? [Y/n] N
[…]
Remove test database and access to it [Y/n] Y
[…]
Reload privilege tables now? [Y/n] Y
All done!
2.6设置Mysql为开机自动启动
sudo/sbin/chkconfigmysqldon
sudo /sbin/chkconfig –list mysqld
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
2.7为Cloudera Manager创建MySQL Databases(本人做集群用)
(1)用root登陆Mysql:$ mysql -u root –p
(2)脚本
create database amon DEFAULT CHARACTER SET utf8;
grant all on amon.* TO ‘amon’@’%’ IDENTIFIED BY ‘amon_password’;
create database smon DEFAULT CHARACTER SET utf8;
grant all on smon.* TO ‘smon’@’%’ IDENTIFIED BY ‘smon_password’;
create database rman DEFAULT CHARACTER SET utf8;
grant all on rman.* TO ‘rman ‘@’%’ IDENTIFIED BY ‘rman_password’;
create database hmon DEFAULT CHARACTER SET utf8;
grant all on hmon.* TO ‘hmon’@’%’ IDENTIFIED BY ‘hmon_password’;
create database hive DEFAULT CHARACTER SET utf8;
grant all on hive.* TO ‘hive’@’%’ IDENTIFIED BY ‘hive_password’;
create database nav DEFAULT CHARACTER SET utf8;
grant all on nav.* TO ‘nav’@’%’ IDENTIFIED BY ‘nav_password’;
(3)执行实例
Create a database for the Activity Monitor. The database name, user name, and password can be anything you want. For example:
mysql> create database amon DEFAULT CHARACTER SET utf8;
Query OK, 1 row affected (0.00 sec)
mysql>grant all on amon.* TO ‘amon’@’%’ IDENTIFIED BY ‘amon_password’;
Query OK, 0 rows affected (0.00 sec)
(3)Create a database for the Service Monitor. The database name, user name, and password can be anything you want. For example:
mysql> create database smon DEFAULT CHARACTER SET utf8;
Query OK, 1 row affected (0.00 sec)
mysql> grant all on smon.* TO ‘smon’@’%’ IDENTIFIED BY ‘smon_password’;
Query OK, 0 rows affected (0.00 sec)
(4)Create a database for the Report Manager. The database name, user name, and password can be anything you want. For example:
mysql> create database rman DEFAULT CHARACTER SET utf8;
Query OK, 1 row affected (0.00 sec)
mysql> grant all on rman.* TO ‘rman ‘@’%’ IDENTIFIED BY ‘rman_password’;
Query OK, 0 rows affected (0.00 sec)
(5)Create a database for the Host Monitor. The database name, user name, and password can be anything you want. For example:
mysql> create database hmon DEFAULT CHARACTER SET utf8;
Query OK, 1 row affected (0.00 sec)
mysql> grant all on hmon.* TO ‘hmon’@’%’ IDENTIFIED BY ‘hmon_password’;
Query OK, 0 rows affected (0.00 sec)
(6)Create a database for the Hive metastore. The database name, user name, and password can be anything you want. For example:
mysql> create database hive DEFAULT CHARACTER SET utf8;
Query OK, 1 row affected (0.00 sec)
mysql> grant all on hive.* TO ‘hive’@’%’ IDENTIFIED BY ‘hive_password’;
Query OK, 0 rows affected (0.00 sec)
(7)Create a database for Cloudera Navigator. The database name, user name, and password can be anything you want. For example:
mysql> create database nav DEFAULT CHARACTER SET utf8;
Query OK, 1 row affected (0.00 sec)
mysql>grant all on nav.* TO ‘nav’@’%’ IDENTIFIED BY ‘nav_password’;
Query OK, 0 rows affected (0.00 sec)
2.8为Mysql设置备份
使用mysqldump,命令格式如下:
mysqldump-h-u-p>/tmp/.sql
For example, to back up database scm_database on the local host as the root user, with the password mypasswd:
mysqldump−pmypasswdscmdatabase>/tmp/scmdatabase−backup.sqlTobackupdatabasescmdatabaseonremotehostmyhost.example.comastherootuser,withthepasswordmypasswd:
mysqldump -hmyhost.example.com -uroot -pcloudera scm_database > /tmp/scm_database-backup.sql
如果你顺利的执行到此处,恭喜你,很顺利,但是本人在实际中遇到了问题,问题描素就是:
1,Access denied for user ‘root’@’localhost’ (using password: NO)
处理方法:密码不对
[root ~]# grep 'temporary password' /var/log/mysqld.log
2017-07-05T07:32:13.291107Z 1 [Note] A temporary password is generated for root@localhost: l(0P<cNuwMd1
执行之后找到密码,登录之后继续上诉的2.5步骤
2,[ERROR] InnoDB: Unable to lock ./ibdata1 error: 11
[Note] InnoDB: Check that you do not already have another mysqld process using the same InnoDB data
or log files.
处理方法:有进程共用mysqlid
mysqld stop
service mysqld stop
ps -ef|grep mysql*
kill -9 对应的进程id
以上基本上可以处理这个问题了之后再重启mysql (service mysqld start),此时进入上诉2.4步骤
3,service mysql start failed
改问题与上诉2问题类似
# lsof -i:3306
查看mysql有没有进行,之后按照2的处理方式进行处理
4, Failed! Error: Your password does not satisfy the current policy requirements
处理方法: 你的密码级别很高,重置的密码级别不高,重设
5,改密码级别
进入mysql之后
set global validate_password_policy=0;
set global validate_password_length=0;
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('root');