LINUX-MYSQL
安装mysql sudo apt-get install mysql-server-5.6 mysql-client-5.6
sudo apt-get install libmysqlclient-dev
重启mysql etc/init.d/mysql restart
sudo service mysql restart
进入配置文件 vi /etc/mysql/my.cnf
vi /etc/mysql/my.cnf
vi /etc/mysql/conf.d
bind-address=0.0.0.0
查看用户权限 use mysql;
SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS query FROM mysql.user;
创建用户 grant all privileges on *.* to 'dj'@'% ' identified by '123' with grant option;
刷新用户配置 FLUSH PRIVILEGES;
查看是否启动listen netstat -anpt
下载yum源安装
wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum install mysql-community-server
启动数据库
systemctl start mysql
systemctl start mysqld
/etc/init.d/mysqld start
设置密码,初始密码为空直接回车然后输出两次新密码
mysql -uroot -p
use mysql;
set password for root@localhost = password('123');
FLUSH PRIVILEGES;
跳过授权登录
其中 --skip-grant-tables 的意思是跳过授权表,通过此参数来跳过输入密码,后面跟得 & 符号是表示设置此进程为后台进程
具体操作过程如下:
1.首先关闭掉MySQL系统服务:
service mysqld stop
2.使用命令跳过输入密码过程:
mysqld_safe --skip-grant-tables &
mysql
也可以回车之后在输入命令: mysql
3.进入 mysql数据库,然后通过语句修改密码:
use mysql
update user set password=password("root1234") where user='root'; //修改用户:root的密码成为:root1234
flush privileges//刷新MySQL的系统权限相关表,否则会出现拒绝访问 忘记输入的话重启mysql服务也可以
mysql大全
1.MySQL版本选择,潜规则:
MySQL5.6: GA 6-12个月 小版本是偶数版本 5.6.40
MySQL5.7: GA 6-12个月 小版本是偶数版本 5.6.40 5.7.17以上版本,(MGR自带高可用)
2.二进制安装MySQL
1)解压
tar xf mysql-5.6.40-linux-glibc2.12-x86_64.tar.gz
2)移动到安装目录
mv mysql-5.6.40-linux-glibc2.12-x86_64 /usr/local/mysql-5.6.40
3)做软连接
ln -s /usr/local/mysql-5.6.40 /usr/local/mysql
4)拷贝启动脚本
cp mysql.server /etc/init.d/mysqld
5)进入初始化目录
cd /usr/local/mysql-5.6.40/scripts
6)创建MySQL用户
[root@elk01 scripts]# useradd mysql -s /sbin/nologin -M
7)安装依赖
yum install libaio-devel -y
8)初始化
[root@elk01 scripts]# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
9)授权
[root@elk01 scripts]# chown -R mysql.mysql /usr/local/mysql*
insert into mysql.user values ('localhost','root',PASSWORD('123'),
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'Y',
'',
'',
'',
'',0,0,0,0,'mysql_native_password','','N');
解决MySQL误删除root用户步骤:
1)停库
[root@elk01 scripts]# /etc/init.d/mysqld stop
2)跳过授权表,网络 启动
[root@elk01 scripts]# mysqld_safe --skip-grant-tables --skip-networking &
3)连接数据库
[root@elk01 ~]# mysql
4)刷新系统授权表
mysql> flush privileges;
5)创建用户
mysql> grant all on *.* to root@'localhost' identified by '123' with grant option;
6)重启MySQL
[root@elk01 ~]# /etc/init.d/mysqld restart
给MySQL设置密码:
[root@elk01 ~]# mysqladmin -uroot -p password '123'
MySQL两种连接方式:
1. TCP/IP
[root@elk01 ~]# mysql -uroot -p123 -h 10.0.0.51
[root@elk01 ~]# mysql -uroot -p123 -h127.0.0.1
2. socket
[root@elk01 ~]# mysql -uroot -p123 -S /root/mysql.sock
[root@elk01 ~]# mysql -uroot -p123 -hlocalhost
[root@elk01 ~]# mysql -uroot -p123
MySQL配置文件:
[server]
[mysqld]
影响到服务端的启动
[client]
[mysql]
影响到客户端的连接
MySQL源码安装:
1)安装依赖
[root@elk02 ~]# yum install -y ncurses-devel libaio-devel cmake
2)解压
[root@elk02 ~]# tar xf mysql-5.6.40.tar.gz
3)创建MySQL用户
[root@elk02 ~]# useradd mysql -s /sbin/nologin -M
4)生成编译文件
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.6.40 \
-DMYSQL_DATADIR=/usr/local/mysql-5.6.40/data \
-DMYSQL_UNIX_ADDR=/usr/local/mysql-5.6.40/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS=all \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DWITH_ZLIB=bundled \
-DWITH_SSL=bundled \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DENABLE_DOWNLOADS=1 \
-DWITH_DEBUG=0
5)编译
make
6)安装
make install
7)做软连接
[root@elk02 mysql-5.6.40]# ln -s /usr/local/mysql-5.6.40 /usr/local/mysql
8)拷贝配置文件
[root@elk02 support-files]# cp my-default.cnf /etc/my.cnf
cp: overwrite ‘/etc/my.cnf’? y
9)拷贝启动脚本
[root@elk02 support-files]# cp mysql.server /etc/init.d/mysqld
10)初始化
[root@elk02 scripts]# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
11)创建socket存放目录
[root@elk02 support-files]# mkdir /usr/local/mysql-5.6.40/tmp
12)授权
[root@elk02 support-files]# chown -R mysql.mysql /usr/local/mysql*
13)添加环境变量
[root@elk02 support-files]# vim /etc/profile.d/mysql.sh
export PATH="/usr/local/mysql/bin:$PATH"
14)加载环境变量
[root@elk02 support-files]# source /etc/profile
15)启动MySQL
[root@elk02 support-files]# /etc/init.d/mysqld start
ubuntu 删除mysql
查看哪些mysql包
dpkg -l | grep mysql
删除这些包
sudo apt-get purge mysql-client mysql-client-5.7 mysql-common mysql-server mysql-server-5.7 mysql-server-core-5.7
停掉服务
sudo /etc/init.d/mysql stop
删除配置
sudo rm /etc/mysql/ -R
sudo rm /var/lib/mysql/ -R
重新安装
sudo apt-get install mysql-client mysql-server
下载yum源安装
1
2
3
|
wget http: / / dev.mysql.com / get / mysql - community - release - el7 - 5.noarch .rpm rpm - ivh mysql - community - release - el7 - 5.noarch .rpm yum install mysql - community - server |
启动数据库
1
|
systemclt start mysql |
设置密码,初始密码为空直接回车然后输出两次新密码
1
|
mysqladmin - uroot - p password |