操作系统:centos 7.2
MySQL版本:mysql-5.6.36
1、卸载当前已经安装的mysql
检查已经安装的mysql
rpm -qa | grep mysql
rpm -qa | grep mariadb
卸载
rpm -e xxxx
rpm -e --nodeps xxxxxx
2. 检查mysql组和用户是否存在,如无创建。
cat /etc/group | grep mysql
cat /etc/passwd | grep mysql
新建组
groupadd mysql
新建用户
useradd -r -g mysql mysql
-r 是表示该用户是系统用户,不能用于登陆系统。
3、安装mysql
tar zxvf mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz
mv mysql-5.6.36-linux-glibc2.5-x86_64/ /usr/local/mysql
新建mysql的数据目录
mkdir /mnt/toolbox/mysql/
赋予mysql用户的数据目录访问权限
chown mysql /mnt/toolbox/mysql/
cd /usr/local/mysql/scripts
./mysql_install_db --basedir=/usr/local/mysql --datadir=/mnt/toolbox/mysql --user=mysql
(5.7.17命令如下:
/usr/local/mysql/bin/mysqld --initialize --user=mysql
/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql/ --datadir=/opt/toolbox/mysql/
)
cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
vi /etc/my.cnf
在[mysqld]后增加下面这句,用于忽略表名的大小写
lower_case_table_names=1
在[mysqld]后增加下面这句,用于解决中文乱码问题
character_set_server=utf8
mysql配置后面会贴出来
将mysql加入到系统启动中。
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
vi /etc/init.d/mysql 添加以下内容
basedir = /usr/local/mysql
datadir = /mnt/toolbox/mysql
添加到系统启动并设置mysql自动启动
chkconfig --add mysql
chkconfig mysql on
启动mysql
service mysql start
修改root密码
vi /etc/my.cnf
在[mysqld]下面增加一行
skip-grant-tables
重启MySQL
service mysql restart
登录mysql 修改root 密码
/usr/local/mysql/bin/mysql -u root
use mysql
update user set password=password('bonatone') where user='root';
flush privileges;
exit
将刚才加上去的skip-grant-tables删掉 ,再重启mysql
创建mysql数据库
create database test default character set utf8 collate utf8_general_ci;
创建用户
create user 'dsy'@'%' identified by 'dsy';
给用户分配权限
grant all on test.* to dsy;
grant all on test.* to dsy@'%' identified by 'dsy';
grant all on test.* to dsy@'localhost' identified by 'dsy';
flush privileges;
检查数据库编码格式
show variables like "%char%";
SET character_set_server='utf8';
flush privileges;
让mysql能执行函数:用root登陆执行下面代码。可以开放触发器权限
SET GLOBAL log_bin_trust_function_creators = 1;
flush privileges;
至此,mysql已经安装完成.
4、安装中可能会遇到的问题及解决办法:
1、mysqld_safe error: log-error set to '/var/log/mariadb/mariadb.log', however file don't exists. Create writable for user 'mysql'.
文件权限问题
解决方法:
mkdir /var/log/mariadb
touch /var/log/mariadb/mariadb.log
chown -R mysql:mysql /var/log/mariadb/
2、[ERROR] SSL error: Unable to get private key from 'server-key.pem'
find / -name server-key.pem
解决方法:
chown -R mysql:mysql /var/lib/mysql/
3、2017-11-08T09:30:33.168222Z 0 [ERROR] Can't start server: Bind on TCP/IP port: Address already in use
2017-11-08T09:30:33.168225Z 0 [ERROR] Do you already have another mysqld server running on port: 3306 ?
2017-11-08T09:30:33.168230Z 0 [ERROR] Aborting
端口占用错误
解决方法:
关闭占用的端口即可
4、/usr/local/mysql/bin/mysqld: Can't create/write to file '/var/run/mariadb/mariadb.pid' (Errcode: 2 - No such file or directory)
没有创建该目录和权限
解决方法:
mkdir /var/run/mariadb/
chown -R mysql:mysql /var/run/mariadb/
5、Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
mysql.sock问题(解决方法很多,这只是其中一个)这是可以由于系统默认的文件位置和文件位置不一致,解决办法找到文件创建软链接
解决方法:
find / -name mysql.sock
ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
网友评论