安装mysql
1、上传已经下载好的mysql安装包到虚拟机下面
2、解压安装包
tar -zxvf mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz
3、移动文件到/usr/local/mysql
mv mysql-5.6.33-linux-glibc2.5-x86_64 /usr/local/mysql
4、针对mysql增加用户
groupadd mysql (如果之前已经添加过 就需要用groupdel mysql或userdel mysql把之前添加的组给删掉)
useradd -g mysql -M mysql
5、将文件存入到/keudox/mysql/data ,并授权
mkdir -p /keduox/mysql/data
chown -R mysql.mysql /keduox/mysql/data
6、初始化MySQL数据库:
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/keduox/mysql/data --user=mysql
出现以下错误:
/usr/local/mysql/scripts/mysql_install_db: /usr/bin/perl: 坏的解释器: 没有那个文件或目录
解决办法:
yum install perl
安装好以后,在次运行
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/keduox/mysql/data --user=mysql
出现:
FATAL ERROR: please install the following Perl modules before executing /usr/local/mysql/scripts/mysql_install_db:
Data::Dumper
解决办法:
yum install -y perl-Module-Install.noarch
安装成功后显示
7.相关配置
进入:/usr/local/mysql
修改 my.cnf文件
8:添加mysqld 成为系统服务并设置自启动
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
9、启动
/etc/init.d/mysqld start
出现以下错误
chmod: 无法访问"/var/log/mariadb/mariadb.log": 没有那个文件或目录
解决办法:
mkdir /var/log/mariadb
10、设置密码
/usr/local/mysql/bin/mysqladmin -u root password '1234'
出现以下错误:
/usr/local/mysql/bin/mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)'
Check that mysqld is running and that the socket: '/tmp/mysql.sock' exists!
ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
11、安装完成后
service mysqld restart (重启mysql)
把mysql设到环境变量里面去
vi /etc/profile
source /etc/profile
登陆方式
mysql -uroot -p新密码进入
12、开启远程访问
//登录数据库
mysql -u root -p1234
>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '1234' WITH GRANT OPTION;
mysql>FLUSH PRIVILEGES;
参考网址:http://blog.csdn.net/quuqu/article/details/51489737
>use mysql;
select Host,User,Password from user;
delete from user where Host<>'%';