MySQL:常见使用问题
admin
2023-05-19 14:22:38
0次

1、Linux 上安装MySQL

安装步骤:

1)解压 tar.gz文件

shell> tar -zxvf mysql-5.7.9-linux-glibc2.5-x86_64.tar.gz

 

2)初始化默认数据库(mysql、performace_schema、sys、information_schema)

在/home/bes/jinuo/mysql 目录下的结构如下:

MySQL:常见使用问题

/home/bes/jinuo/mysql
                     /mysql-5.7.9-glibc2.5-x86_64
                           /bin
                           /docs
                           /include
                           /lib
                           /man
                           /share
                           /support-files
                    /test
                         /ins1
                              /my-default.cnf

MySQL:常见使用问题

 

拷贝 support-files 目录到你想要做mysql实例的目录下,并编辑如下:

MySQL:常见使用问题

[mysqld]
basedir=/home/bes/jinuo/mysql/mysql-5.7.9-linux-glibc2.5-x86_64
datadir=/home/bes/jinuo/mysql/test/ins1/datadir
port=36001
server_id=36001
socket=/home/bes/jinuo/mysql/test/ins1/mysql.sock
log-error=/home/bes/jinuo/mysql/test/mysqld.log
explicit_defaults_for_timestamp=true
character-set-server=utf8
collation-server=utf8_general_ci
skip-host-cache
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

MySQL:常见使用问题

然后执行如下命令初始化:

普通用户可以直接执行如下命令:

shell> bin/mysql_install_db    # Before MySQL 5.7.6shell> bin/mysqld --initialize   # MySQL 5.7.6 and up

 如果是操作每户的root用户创建mysql实例,创建实例时,需要指定为哪个用户创建的实例。

也就是说,如果你是一个普通用户 hello, 你可以使用上面 的命令直接 创建自己的实例。

如果要让root用户给你创建实例,需要在上面命令后面加上 --user=hello 参数。

 

root用户:
shell>mysqld --defaults-file=/your/mysql/cnf/path --initialize-insecure --user=username
>mysqld --defaults-=/your/mysql/cnf/path --initialize-insecure

 

在初始化时,会为mysql root用户 创建一个临时密码。临时密码的位置可以这样找到:

               

MySQL:常见使用问题

MySQL 5.6.x :

A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER !
You will find that password in '/root/.mysql_secret'.
You must change that password on your first connect,
no other statement but 'SET PASSWORD' will be accepted.
See the manual for the semantics of the 'password expired' flag.
Also, the account for the anonymous user has been removed.

MySQL:常见使用问题

MySQL:常见使用问题

MySQL 5.7.x :

如果初始化时使用的是  --initialize:
# tail -n1 /home/bes/jinuo/mysql/test/ins1/mysqld.log
2016-12-11T07:47:58.199154Z 1 [Note] A temporary password is generated for root@localhost: wzgds/:Kf2,g

如果
初始化时使用的是  --initialize-insecure:

  # tail -n1 /var/log/mysql/error.log
  2016-12-11T07:51:28.506142Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option

MySQL:常见使用问题

 所以,如果是5.7之上的版本,建议使用  --initialize-insecure方式来创建实例。这样就可以直接使用mysqladmin来修改root密码了。参见4)。

 

 

3)启动数据库

启动MySQL Server:

shelll> /home/bes/jinuo/mysql/mysql-5.7.9-linux-glibc2.5-x86_64/bin/mysqld --defaults-file=/home/bes/jinuo/mysql/test/ins1/my-default.cnf &

 

4)知道密码情况下,修改密码

mysqladmin 提供了一套mysql的管理命令,其中有一个是password命令,用于修改密码的。使用mysqladmin 来修改密码的前提是你知道密码,因为它内部是先使用现有登录到mysql server,然后修改密码。

可以直接使用mysqladmin命令来修改密码。例如修改root密码,由安装后的 空密码修改为 12345678

mysqladmin -u root --socket=/home/bes/mysql/mysql.sock password 12345678

如果在使用过程中,想要更换密码由12345678变成123456:

mysqladmin -u root -p 12345678 --socket=/home/bes/mysql/mysql.sock password 123456

修改其它用户的密码,是同样 的方式。

 

5)为root授权限

 

mysql> grant all on *.* to 'root'@'%' identified by 'yourRootPassword';

 

2、单机多实例安装

如果在一台机器上,要安装多个mysql实例,只需要将重复执行 1中的2)3)4)5)就可以了。

 

 

3、 不知root密码情况下,修改root密码、授权

该方式适用于,有root密码,但是不知道root 密码情况下。

 

       a: 停止 MySQL Server

       b: 绕过授权检查方式启动MySQL Server

            

shell> /home/bes/jinuo/mysql/mysql-5.7.9-linux-glibc2.5-x86_64/bin/mysqld --defaults-file=/home/bes/jinuo/mysql/test/ins1/my-default.cnf --skip-grant-tables &

       c: root用户登录到mysql server上,并切换到mysql 库

  

shell> /home/bes/jinuo/mysql/mysql-5.7.9-linux-glibc2.5-x86_64/bin/mysql --socket=/home/bes/jinuo/mysql/test/ins1/mysql.sock -uroot -p

mysql> use mysql;

 

       d: 修改root 用户的密码: 

    

mysql> update mysql.user set authentication_string = password('mypassword') where user = 'root';
mysql> flush privileges;
mysql> quit;

        e: 停止mysql server,正常启动。

        正常启动的方式在前面 3)中已说过。

        f: root 登录后,进行授权调整:

       

shell> /home/bes/jinuo/mysql/mysql-5.7.9-linux-glibc2.5-x86_64/bin/mysql --socket=/home/bes/jinuo/mysql/test/ins1/mysql.sock -uroot -p
Enter Password

mysql> grant all on *.* to 'root'@'%' identified by 'yourRootPassword';


相关内容

热门资讯

空调连续工作多久需要停机休息 空调连续工作的时间取决于多个因素,包括空调的型号、功率、使用环境和维护情况等。一般来说,空调可以连续...
空调哪个符号是除湿的 空调除湿功能通常用一个水滴形状的符号表示。不同品牌和型号的空调遥控器可能会有所差异,但一般来说,除湿...
格力空调多长时间加一次氟利昂 1、一般情况下,空调对氟利昂的使用量是非常小的,所以在空调使用了四年左右的时候再考虑加也没问题。2、...
空调用多长时间需要加氟一次 一般情况下是五年。当出现以下这几种情况时,空调才需要加氟。1、空调的室内机和室外机各有两个接口,当接...
格调生活·C标思享荟:卡萨帝在... 9月12日的郑州龙湖金融岛,夜风轻拂,灯光璀璨。“C标时刻共传奇——卡萨帝思享荟暨20周年品牌盛典郑...
品牌价值破千亿、高端份额持续领... 9月12日,“C标时刻共传奇——卡萨帝思享荟暨20周年品牌盛典郑州站”在郑州龙湖金融岛举办。2026...
空调主板坏了修800还是换新的 空调主板坏了是修还是换新,需要考虑多个因素,以下是一些建议:1. 维修成本:如果维修费用较低,比如 ...
空调开多久需要休息多长时间 问题:空调开多久需要休息多长时间回答:1、在使用空调的过程中,一般空调开7~8个小时左右需要休息2~...
中央空调多长时间清洗一次 1、一般空调开机前清洗一次即可,空调开机中间时段再清洗一次,空调关机时清洗一次,这样比较合理。2、空...
中央空调氟利昂多久加一次 看空调制热和制冷程度,很多人的观点认为氟利昂必须一年放一次,其实这个观点是错误的,理解上面有点偏差,...