linux版本:html
一、下载安装包“mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz” mysql
# 安装依赖 yum -y install perl perl-devel autoconf libaio
二、把下载的安装包移动到/usr/local/下。linux
三、解压sql
tar zxvf mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz
四、复制解压后的mysql目录到系统的本地软件目录数据库
cp mysql-5.6.33-linux-glibc2.5-x86_64 /usr/local/mysql -r
五、添加系统mysql组和mysql用户服务器
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
注意:Because the user is required only for ownership purposes, not login purposes, the useradd command uses the -r and -s /bin/false options to create a user that does not have login permissions to your server host. Omit these options if your useradd does not support them.
六、进入安装mysql软件目录,修改目录拥有者为mysql用户ide
cd mysql/
chown -R mysql:mysql ./
七、安装数据库,此处可能出现错误。ui
./scripts/mysql_install_db --user=mysql
问题1:FATAL ERROR: please install the following Perl modules before executing scripts/mysql_install_db:
Data::Dumper
#解决方法:
yum install -y perl-Data-Dumper
问题2:Installing MySQL system tables.../usr/local/mysql/bin/mysqld: error while loading shared 缘由是:缺乏libaio库文件
#解决方法:
yum install libaio* -y
八、修改当前目录拥有者为root用户spa
chown -R root:root ./
九、修改当前data目录拥有者为mysql用户.net
chown -R mysql:mysql data
============== 到此数据库安装完毕 =============
十、添加mysql服务开机自启动
添加开机启动,把启动脚本放到开机初始化目录。
cp support-files/mysql.server /etc/init.d/mysql # 赋予可执行权限 chmod +x /etc/init.d/mysql # 添加服务 chkconfig --add mysql # 显示服务列表 chkconfig --list
若是看到mysql的服务,而且3,4,5都是on的话则成功,若是是off,则执行
chkconfig --level 345 mysql on
十一、启动mysql服务
#建立缺乏的文件夹
mkdir /var/log/mariadb
service mysql start
正常提示信息:Starting MySQL. SUCCESS!
十二、把mysql客户端放到默认路径
ln -s /usr/local/mysql/bin/mysql /usr/local/bin/mysql
经过使用 mysql -uroot -p 链接数据库(默认数据库的root用户没有密码,这个须要设置一个密码)。
----------------------建立本身的用户------------------------------------
添加新用户
容许本地 IP 访问 localhost, 127.0.0.1
create user 'test'@'localhost' identified by '123456';
容许外网 IP 访问
create user 'test'@'%' identified by '123456';
刷新受权
flush privileges;
为用户建立数据库
create database test DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
为新用户分配权限
授予用户经过外网IP对于该数据库的所有权限
grant all privileges on `testdb`.* to 'test'@'%' identified by '123456';
授予用户在本地服务器对该数据库的所有权限
grant all privileges on `testdb`.* to 'test'@'localhost' identified by '123456';
刷新权限
flush privileges;
退出 root 从新登陆
exit
用新账号 test 从新登陆,因为使用的是 % 任意IP链接,因此须要指定外部访问IP
mysql -u test -h 115.28.203.224 -p
------------------在mysql -uroot -p下建立user的另外一方法-----------------------------------------
GRANT USAGE ON *.* TO 'admin'@'localhost' IDENTIFIED BY 'admin' WITH GRANT OPTION;
------------------出现中文乱码问题的解决-----------------------------------------
https://blog.csdn.net/sayoko06/article/details/76679380