注意:
1、以下操作用户为root
2、安装版本要保持一致,安装mysql-5.6.42-linux-glibc2.12-x86_64.tar.gz版本,采用该步骤报错!
https://link.zhihu.com/?target=https%3A//dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz
tar -zxvf mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz
mv mysql-5.6.33-linux-glibc2.5-x86_64 /usr/local/mysql
groupadd mysql
useradd -r -g mysql mysql
// useradd -g mysql -M mysql
mkdir -p /home/mysql/data
chown -R mysql:mysql /home/mysql/data //-R : 处理指定目录以及其子目录下的所有文件
cd /usr/local/mysql/scripts]
./mysql_install_db --basedir=/usr/local/mysql --datadir=/home/mysql/data --user=mysql
如果报错:
/usr/local/mysql/scripts/mysql_install_db:/usr/bin/perl:坏的解释器:没有那个文件或目录
解决:yum install perl
如果报错:
FATAL ERROR:please install the following Perl modules before executing
/usr/local/mysql/scripts/mysql_install_db
解决:yum -y install perl-Module-Install.noarch
[/usr/local/mysql/my.cnf]
basedir = /usr/local/mysql
datadir = /home/mysql/data
port = 3306
将mysql服务启动文件放到/etc/init.d目录中
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
将mysqld作为linux的服务
chkconfig --add mysqld
将mysqld服务作为自启动服务
chkconfig mysqld on
出现以下错误:
chmod:无法访问“/var/log/mariadb/mariadb.log":没有那个文件或目录
解决办法: mkdir /var/log/mariadb
chkconfig --list 显示服务列表
如果看到mysql的服务,并且3,4,5都是on的话则成功,如果是off,则键入
chkconfig --level 345 mysql on
/etc/init.d/mysqld start
ps -ef|grep mysql 看到mysql服务说明启动成功
// ps - report a snapshot of the current processe
// -e Select all processes. Identical(相同的) to -A.
/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 the socket:'/tmp/mysql.scok‘ exists !
find / -name mysql.sock
ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
/usr/local/mysql/bin/mysqladmin -u root password "1234"
service mysqld restart
mysql -uroot -p1234
-bash:mysql:未找到命令
cd /usr/local/mysql
echo "export MYSQL_HOME=/usr/local/mysql" >> /etc/profile
echo "export PATH=$PATH:$MYSQL_HOME/bin" >> /etc/profile
//成功了!
[root@master106 bin]# mysql -uroot -p1234
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.42 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
开启远程访问
登录数据库
mysql -uroot -p1234
mysql>use mysql
// %为所有ip都能够访问
mysql>update user set host = '%' where user = 'root';
或者直接添加一条语句
mysql>insert into user(host,user,password)values('172.16.2.106','root',password('1234'));
//查看修改
mysql>select host,user from user;
// 推送设置到内存或者重启服务器也行
mysql>FLUSH PRIVILEGES
(推荐使用)
http://www.cnblogs.com/ycsfwhh/archive/2012/08/07/2626597.html
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'IDENTIFIED BY '1234' WITH GRANT OPTION;
mysql>FLUSH PRIVILEGES
*.* 所有数据库下的所有表
root哪一个用户可以访问
% 所有主机可以访问,如果希望某一台主机可以访问,将%改成ip地址
mypassword:访问者以什么密码访问
默认时,mysql安装完成后,会在mysql.user表中有多个用户存在,表示本机的用户就会有几个,当用户连接mysql时候,有可能找到没有设置密码的数据,就会存在,有的人能够连接,有的人连接不上。所以为了统一。把mysql.user表中密码为空的用户进行删除。也可以只留下%的用户。
mysql>delete from mysql.user where host <> %;
最好在删除之后,将mysql服务重启
mysql>service mysqld restart
http://www.cnblogs.com/ycsfwhh/archive/2012/08/07/2626597.html
window mysql安装
https://dev.mysql.com/downloads/mysql/