非root权限安装mysql

所需软件:

  • mysql的安装包
  • cmake的安装包

因为我用的linux平台已经事先安装好了cmake,所以我在网上找了一份安装教程,安装包可以到我的百度网盘里提取。链接:https://pan.baidu.com/s/1bs9y0zhXkRaYhXRSXg_FpA 密码:sy4z

cmake安装:

  1.   ./configure --prefix=$HOME/local/cmake-2.8.12.2
  2.   make
  3.   make install

至此,cmake就ok了,你可以在 $HOME/local/cmake-2.8.12.2/bin 目录里面看到cmake了。为了不用每次都输入这么长串的地址才能访问cmake,当然有必要把$HOME/local/cmake-2.8.12.2/bin放到环境变量里面了。

  1. vi ~/.bash_profile
  2. 在 path的后面加上 $HOME/local/cmake-2.8.12.2/bin
  3. source ~/.bash_profile

如此一来,就可以和cmake亲密接触了。不信,你在任意路径输入 cmake –version看看。


mysql安装包

   mysql-5.6.40,网盘链接,链接:https://pan.baidu.com/s/1skeO_Egp6c9NJlDPUw1GeQ 密码:3m1k 

mysql安装:

    我是设置~/local/  作为mysql的安装目录, mysql包下载至~/software/ 目录下

    1、解压安装包

tar  -zxvf  mysql-5.6.40

    2、因为安装不需要root,所以我们需要在我们自己目录下配置一些文件或者文件夹来存放数据以及日志

mkdir ~/local/mysql    #安装目录
cd ~/local/mysql
mdkir data            #数据存放
touch mysql_3307.sock
mdkir tmp
mkdir -p log           #日志有关文件夹
cd log    
touch mysql.err        #报错信息
touch mysql.log        #日志信息

    3、进行cmake编译

$cd mysql-5.6.40
$cmake . -DCMAKE_INSTALL_PREFIX=~/local/mysql -DMYSQL_UNIX_ADDR=~/local/mysql/mysql_3307.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=~/local/mysql/data -DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3307
----------漫长的等待----------
$make
----------漫长的等待----------
$make install
----------漫长的等待----------

  4、配置mysql

$cd ~/local/mysql
$cp support-files/my-default.cnf ./my.cnf
$vi my.cnf      #示例
[client]
port = 3307        #端口可以改
socket = /amoydx/USER/huangkefei/software/mysql/mysql_3307.sock
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M 
         
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin

[mysqld]     
# These are commonly set, remove the # and set as required.
basedir = /amoydx/USER/huangkefei/software/mysql
datadir = /amoydx/USER/huangkefei/software/mysql/data
port = 3307        #端口可以改
socket = /amoydx/USER/huangkefei/software/mysql/mysql_3307.sock
tmpdir = /amoydx/USER/huangkefei/software/mysql/tmp
log-error = /amoydx/USER/huangkefei/software/mysql/log/mysql.err
general_log_file = /amoydx/USER/huangkefei/software/mysql/log/mysql.log
general_log = 1
# server_id = .....

  5、安装mysql

#在mysql目录下
./scripts/mysql_install_db --basedir=~/local/mysql --datadir=~/local/mysql/data --user=huangkefei --defaults-file=~/local/mysql/my.cnf --socket=~/local/mysql/mysql_3307.sock

   6、启动mysql

nohup ./bin/mysqld_safe  --defaults-file=~/local/mysql/my.cnf &

  

在这个地方,我出现了报错: Table 'mysql.plugin' doesn't exist

    解决方案:

$ ./scripts/mysql_install_db --basedir=~/local/mysql --datadir=~/local/mysql/data
#输出记录如下
'''
Installing MySQL system tables...2018-05-29 09:28:24 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-05-29 09:28:24 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2018-05-29 09:28:24 0 [Note] /amoydx/USER/huangkefei/software/mysql/bin/mysqld (mysqld 5.6.40) starting as process 963 ...
2018-05-29 09:28:24 963 [Warning] Buffered warning: Changed limits: max_open_files: 1024 (requested 5000)

2018-05-29 09:28:24 963 [Warning] Buffered warning: Changed limits: table_open_cache: 431 (requested 2000)

2018-05-29 09:28:24 963 [Note] InnoDB: Using atomics to ref count buffer pool pages
2018-05-29 09:28:24 963 [Note] InnoDB: The InnoDB memory heap is disabled
2018-05-29 09:28:24 963 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2018-05-29 09:28:24 963 [Note] InnoDB: Memory barrier is not used
2018-05-29 09:28:24 963 [Note] InnoDB: Compressed tables use zlib 1.2.3
2018-05-29 09:28:24 963 [Note] InnoDB: Not using CPU crc32 instructions
2018-05-29 09:28:24 963 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2018-05-29 09:28:24 963 [Note] InnoDB: Completed initialization of buffer pool
2018-05-29 09:28:24 963 [Note] InnoDB: Highest supported file format is Barracuda.
2018-05-29 09:28:24 963 [Note] InnoDB: 128 rollback segment(s) are active.
2018-05-29 09:28:24 963 [Note] InnoDB: Waiting for purge to start
2018-05-29 09:28:24 963 [Note] InnoDB: 5.6.40 started; log sequence number 1600617
2018-05-29 09:28:24 963 [Note] Binlog end
2018-05-29 09:28:24 963 [Note] InnoDB: FTS optimize thread exiting.
2018-05-29 09:28:24 963 [Note] InnoDB: Starting shutdown...
2018-05-29 09:28:26 963 [Note] InnoDB: Shutdown completed; log sequence number 1625997
OK

Filling help tables...2018-05-29 09:28:26 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-05-29 09:28:26 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2018-05-29 09:28:26 0 [Note] /amoydx/USER/huangkefei/software/mysql/bin/mysqld (mysqld 5.6.40) starting as process 1105 ...
2018-05-29 09:28:26 1105 [Warning] Buffered warning: Changed limits: max_open_files: 1024 (requested 5000)

2018-05-29 09:28:26 1105 [Warning] Buffered warning: Changed limits: table_open_cache: 431 (requested 2000)

2018-05-29 09:28:26 1105 [Note] InnoDB: Using atomics to ref count buffer pool pages
2018-05-29 09:28:26 1105 [Note] InnoDB: The InnoDB memory heap is disabled
2018-05-29 09:28:26 1105 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2018-05-29 09:28:26 1105 [Note] InnoDB: Memory barrier is not used
2018-05-29 09:28:26 1105 [Note] InnoDB: Compressed tables use zlib 1.2.3
2018-05-29 09:28:26 1105 [Note] InnoDB: Not using CPU crc32 instructions
2018-05-29 09:28:26 1105 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2018-05-29 09:28:26 1105 [Note] InnoDB: Completed initialization of buffer pool
2018-05-29 09:28:26 1105 [Note] InnoDB: Highest supported file format is Barracuda.
2018-05-29 09:28:26 1105 [Note] InnoDB: 128 rollback segment(s) are active.
2018-05-29 09:28:26 1105 [Note] InnoDB: Waiting for purge to start
2018-05-29 09:28:26 1105 [Note] InnoDB: 5.6.40 started; log sequence number 1625997
2018-05-29 09:28:26 1105 [Note] Binlog end
2018-05-29 09:28:26 1105 [Note] InnoDB: FTS optimize thread exiting.
2018-05-29 09:28:26 1105 [Note] InnoDB: Starting shutdown...
2018-05-29 09:28:27 1105 [Note] InnoDB: Shutdown completed; log sequence number 1626007
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

  /amoydx/USER/huangkefei/software/mysql/bin/mysqladmin -u root password 'new-password'
  /amoydx/USER/huangkefei/software/mysql/bin/mysqladmin -u root -h login-1-1.local password 'new-password'

Alternatively you can run:

  /amoydx/USER/huangkefei/software/mysql/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:

  cd . ; /amoydx/USER/huangkefei/software/mysql/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl

  cd mysql-test ; perl mysql-test-run.pl

Please report any problems at http://bugs.mysql.com/

The latest information about MySQL is available on the web at

  http://www.mysql.com

Support MySQL by buying support/licenses at http://shop.mysql.com

WARNING: Found existing config file /amoydx/USER/huangkefei/software/mysql/my.cnf on the system.
Because this file might be in use, it was not replaced,
but was used in bootstrap (unless you used --defaults-file)
and when you later start the server.
The new default config file was created as /amoydx/USER/huangkefei/software/mysql/my-new.cnf,
please compare it with your file and take the changes you need.

WARNING: Default config file /etc/my.cnf exists on the system
This file will be read by default by the MySQL server
If you do not want to use this, either remove it, or use the
--defaults-file argument to mysqld_safe when starting the server
'''
再重新启动mysql,就OK了。

   7、查看mysql是否在运行

$ ps
  PID TTY          TIME CMD
 5927 pts/3    00:00:00 mysqld_safe
 6107 pts/3    00:00:00 mysqld
 6378 pts/3    00:00:00 ps
27268 pts/3    00:00:00 bash

  

基本配置:

1、修改root密码

$./bin/mysqladmin --socket=~/local/mysql/mysql_3307.sock -uroot password 123456

2、本机登录mysql

$./bin/mysql --socket=~/local/mysql/mysql_3307.sock -uroot password 123456

3、创建用户(授权)

$./bin/mysql -u root -p
Enter password: ******
    ./bin/mysql: Unknown OS character set 'ISO-8859-15'.
./bin/mysql: Switching to the default character set 'utf8'.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.40-log Source distribution

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>CREATE USER 'kefei.huang'@'10.6.16.112' IDENTIFIED BY '*******';
Query OK, 0 rows affected (0.00 sec)
mysql> grant all privileges on *.* to 'kefei.huang'@'%' identified by '*******';
Query OK, 0 rows affected (0.00 sec)
##查看所有用户
mysql> SELECT User, Host, Password FROM mysql.user;
+-------------+-----------------+-------------------------------------------+
| User        | Host            | Password                                  |
+-------------+-----------------+-------------------------------------------+
| root        | localhost       | *E4A535F211A0495CF91B874473B80C07828F31B2 |
| root        | login-1-1.local |                                           |
| root        | 127.0.0.1       |                                           |
| root        | ::1             |                                           |
|             | localhost       |                                           |
|             | login-1-1.local |                                           |
| kefei.huang | 10.6.16.112     | *E4A535F211A0495CF91B874473B80C07828F31B2 |
| kefei.huang | %               | *E4A535F211A0495CF91B874473B80C07828F31B2 |
+-------------+-----------------+-------------------------------------------+
8 rows in set (0.00 sec)
##查看数据库下所有表格
mysql> use mysql;        #切换数据库
mysql> show tables;        #查看所有表格
mysql> show grants for 'cactiuser'@'%';    #查看用户权限

好了,基本上就这些了。 有问题大家可以留言。

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

heianduck

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值