centos7(脚本)安装配置mysql

安装mysql5.7使用脚本文件进行安装,运行完毕即可安装mysql;

安装后的mysql设置:

设置密码

mysql编码问题

mysql官网安装文档:https://dev.mysql.com/doc/refman/8.0/en/linux-installation-yum-repo.html

创建脚本:vim mysql-install.sh

安装脚本文件mysql-install.sh内容:

# !/bin/bash
# install mysql.
echo y | yum -y install mysql
if [  $? -ne  0 ];then
echo "yum install mysql failed"
exit 1
fi

# download mysql-server5.7
wget http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
if [ $? -ne 0 ];then
    echo "wget is not installed"
    yum -y install wget
    wget http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
    if [ $? -ne 0 ];then
      echo "download mysql-server failed."
      exit 1
    fi
fi

# install mysql-server
rpm -ivh mysql57-community-release-el7-7.noarch.rpm
if [ $? -ne 0 ];then
    echo "rpm -ivh mysql57-community-release-el7-7.noarch.rpm failed"
    exit 1
fi
# install mysql-community-server
yum install -y mysql-community-server
if [ $? -ne 0 ];then
    echo "rpm -ivh mysql-community-server failed"
    exit 1
fi

# install mysql-devel
yum -y install mysql-devel
if [ $? -ne 0 ];then
    echo "yum install mysql-devel failed"
    exit 1
fi

# set character-set in /etc/my.cnf
if [ ! -f "/etc/my.cnf" ];then
    echo "/etc/my.cnf doesn't exists. set character-set failed."
    exit 1
fi
echo "[mysql]">> /etc/my.cnf
echo "default-character-set=utf8">> /etc/my.cnf

#restart mysql
systemctl restart mysqld
if [ $? -ne 0 ];then
    echo "service mysqld restart failed."
    exit 1
fi

设置权限:chmod u=rwx,g=rx,o=rx mysql-install.sh

脚本运行安装mysql:./mysql-install.sh

设置密码:

1、修改 vim /etc/my.cnf,在 [mysqld] 小节下最后添加一行:skip-grant-tables=1

这一行配置让 mysqld 启动时不对密码进行验证

2、重启 mysqld 服务:systemctl restart mysqld

3、使用 root 用户登录到 mysql:mysql -u root 

4、切换到mysql数据库:use mysql;,更新 user 表:

update user set authentication_string = password('root'), password_expired = 'N', password_last_changed = now() where user = 'root';

在之前的版本中,密码字段的字段名是 password,5.7版本改为了 authentication_string

5、退出 mysql:quit,编辑 /etc/my.cnf 文件,删除 skip-grant-tables=1 的内容

6、重启 mysqld 服务,再用新密码登录即可

mysql编码问题:

进入mysql:mysql -uroot -p(密码)

1、查看编码使用:SHOW VARIABLES LIKE 'character_set_%'; 

2、在/etc/my.cnf中追加

[mysql] default-character-set=utf8

3、修改服务器编码:set character_set_server = utf8; 

4、修改创建的数据库的默认编码:set character_set_database = utf8;

5、sql测试:

create database test_encode;

use test_encode;

create table person(name varchar(50)) default charset=utf8;

INSERT INTO person VALUES("谷传杭");

select * from person;

查看结果是否正常显示中文

 

ok,以上内容总结至多个博客。。。

https://blog.csdn.net/guchuanhang/article/details/78612100

https://www.cnblogs.com/activiti/p/7810166.html

https://blog.csdn.net/guchuanhang/article/details/78612536

 

如果帮到你请点赞☺☺☺

 

posted @ 2018-12-28 10:52  夯实点  阅读(1115)  评论(0编辑  收藏  举报