1.卸载mysql
1.1.查找是否安装了MySQL
rpm -qa | grep -i mysql
1.2.卸载
sudo rpm -e --nodeps mysql-libs-5.1.73-8.el6_8.x86_64
2.获取mysql文件注意这里的el6-10即适配RHEL(Red Hat Enterprise Linux)6.10的版本,如果下载了其它版本后面的安装过程中可能会报错)
[bigdata@hdp-slave1 etc]$ sudo wget http://repo.mysql.com/mysql57-community-release-el6-10.noarch.rp
3.安装第二步下载的rpm文件
[bigdata@hdp-slave1 etc]$ sudo yum -y localinstall mysql57-community-release-el6-10.noarch.rpm
4.装MySQL服务
[bigdata@hdp-slave2 etc]$ sudo yum -y install mysql-community-server
5.启动mysql
[bigdata@hdp-slave1 etc]$ sudo service mysqld start
6.1.获取初始化密码(未成功,采用的6.2方法)
[bigdata@hdp-slave1 etc]$ sudo grep "password" /var/log/mysqld.log
mysql> set global validate_password_policy=0;#降低密码难易程度
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('pythonniu');
6.2.开启无密码登录模式,并修改密码,设置远程访问权限
[bigdata@hdp-slave1 etc]$ sudo grep "password" /var/log/mysqld.log
1).开启无密码登录模式,并修改密码
[bigdata@hdp-slave1 etc]$ cd /etc/
[bigdata@hdp-slave1 etc]$ sudo vi my.cnf
在[mysqld]这个条目下加入 skip-grant-tables 保存退出后重启mysql
[bigdata@hdp-slave1 etc]$ sudo service mysqld restart
[bigdata@hdp-slave1 etc]$ mysql -u root -p
mysql> use mysql;
mysql> update user set password=password("新密码") where user="root";
2)设置远程访问权限
任何主机
mysql>GRANT ALL PRIVILEGES ON . TO 'root'@'%' IDENTIFIED BY '你的密码' WITH GRANT OPTION;
刷新权限
mysql>flush privileges;
7.设置字符集
修改my.cnf
新添加[mysql],补充[mysqld],对照以下内容
[mysql]
default-character-set=utf8
[mysqld]
#设置utf8编码
character-set-server = utf8
collation-server = utf8_general_ci
skip-character-set-client-handshake
#MYSQL设置不区分大小写
lower_case_table_names=1
8.原始my.cnf文件展示
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[bigdata@hdp-slave2 etc]$ cat my.cnf.bak
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid