zoukankan      html  css  js  c++  java
  • ubuntu12.04上手动安装mysql

    1、从网下载mysql的tar包, 我下载的是5.6的版本,如下: mysql-5.6.26-linux-glibc2.5-x86_64.tar.gz

    2、上传到ubuntu上去,直接拷贝或是使用工具都可以,在我的用户imx下的download下。

    3、把mysql-5.6.26-linux-glibc2.5-x86_64.tar.gz拷贝到/usr/local下, 使用命令

    #tar -xzvf mysql-5.6.26-linux-glibc2.5-x86_64.tar.gz

    4、重命名解压出来的文件夹: sudo mv mysql-5.6.26-linux-glibc2.5-x86_64 mysql 

    5、修改Mysql的属主与属组为mysql用户

    #sudo chown -R mysql:mysql mysql

    6、安装依赖包,如果未用安装的话,否则在安装的时候报错

    sudo apt-get install libaio-dev

    7、执行mysql安装脚本

    sudo scripts/mysql_install_db --user=mysql

    8、将mysql配置文件拷贝到etc目录(全局配置)

    注意:5.6版本的默认配置文件名称由原先的my-medium变更为了my-default。

    sudo cp support-files/my-default.cnf /etc/my.cnf

    在此配置文件里配置mysql的参数,如果不修改的话,则使用默认的参数

    9、启动mysql

    sudo bin/mysqld_safe --user=mysql &

    此命令是启动mysqld的daemon, 即mysqld

    10、配置mysql客户端, 即mysql的客户端mysql shell, 

    sudo cp support-files/mysql.server /etc/init.d/mysql.server

    也可以修改mysql, 

    11、将mysql/bin/mysql命令加入到用户命令中,或将mysql/bin目录加入path

    加入用户命令:

    sudo ln -s /usr/local/mysql/bin/mysql /usr/local/bin/mysql

    加入环境变量:

    export PATH=$PATH:/usr/local/mysql/bin

    12、查看mysql运行状态

    sudo service mysql.server status
    如果运行正常,会显示 MySQL running。

    如果显示 not running,应该是前面没有启动服务,可直接用service mysql.server start启动

    sudo service mysql.server [status|start|stop] 

    13、让mysql开机启动[defaults],取消开机启动[remove]

    sudo update-rc.d -f mysql.server defaults  [remove]

    14、初始化mysql root用户密码

    sudo bin/mysqladmin -u root password '密码文字'

    15、查看mysql的进程:

    #ps -A|grep mysql 
       显示类似:
      1829 ?        00:00:00 mysqld_safe
       1876 ?        00:00:31 mysqld
      2.#kill -9 1829
      3.#kill -9 1876

    ps -ef |grep mysql

    16、允许root用户远程登录

    1>进入mysql: mysql –u root –p

    2>改变数据库: use mysql;

    3>从任意主机登录: grant all privileges on *.* to root@"%" identified by "密码文字" with grant option;

    4>从指定主机登录: grant all privileges on *.* to root@"192.168.1.101" identified by "passw0rd" with grant option;

    5>授权生效: flush privileges;

    6>查看host为%授权是否添加: select * from user;

    7>查看数据库字符集: show variables like 'character%';

    启动完mysql后,我们接着可以测试一下,使用“mysql”命令来进入mysql数据库的控制台
    $mysql -u root

    在这里之所以用-u root是因为我现在是一般用户(imx6),如果不加-u root的话,mysql会以为是imx6在登录。注意,我在这里没有进入根用户模式,因为没必要。一般来说,对mysql中的数据库进行操作,根本没必要进入根用户模式,只有在设置时才有这种可能。

    进入mysql之后,最要紧的就是要设置Mysql中的root用户密码了,否则,Mysql服务无安全可言了。
    mysql> GRANT ALL PRIVILEGES ON *.* TO root@localhost IDENTIFIED BY "123456";
    如果需要使用root从其他机器远程访问可以使用
    mysql> GRANT ALL PRIVILEGES ON *.* TO root@“%” IDENTIFIED BY "123456";
    注意,我这儿用的是123456做为root用户的密码,但是该密码是不安全的,请大家最好使用大小写字母与数字混合的密码,且不少于8位。

    配置文件参考:

    [html] view plain copy
     
     在CODE上查看代码片派生到我的代码片
      1. # For advice on how to change settings please see  
      2. # http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html  
      3. # *** DO NOT EDIT THIS FILE. It's a template which will be copied to the  
      4. # *** default location during install, and will be replaced if you  
      5. # *** upgrade to a newer version of MySQL.  
      6.   
      7. [client]  
      8. port        = 3306  
      9. default-character-set=utf8  
      10. # Here is entries for some specific programs  
      11. # The following values assume you have at least 32M ram  
      12.   
      13. [mysqld]  
      14. character_set_server=utf8  
      15. lower_case_table_names=1  
      16. init_connect='SET NAMES utf8'  
      17.   
      18. lower_case_table_names=1  
      19.   
      20. max_connections=3000    
      21. max_allowed_packet = 32M   
      22.   
      23. thread_cache_size = 16    
      24. thread_concurrency = 8    
      25.   
      26. query_cache_size = 128M    
      27.   
      28. # Remove leading # and set to the amount of RAM for the most important data  
      29. # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.  
      30. innodb_buffer_pool_size = 128M  
      31.   
      32. # Remove leading # to turn on a very important data integrity option: logging  
      33. # changes to the binary log between backups.  
      34. # log_bin  
      35.   
      36. # These are commonly set, remove the # and set as required.  
      37. basedir = .....  
      38. datadir = .....  
      39. port = .....  
      40. server_id = .....  
      41. socket = .....  
      42.   
      43. # Remove leading # to set options mainly useful for reporting servers.  
      44. # The server defaults are faster for transactions and fast SELECTs.  
      45. # Adjust sizes as needed, experiment to find the optimal values.  
      46.  join_buffer_size = 16M  
      47.  sort_buffer_size = 16M  
      48. read_rnd_buffer_size = 2M   
      49.   
      50. sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES   
      51.   
      52. [mysqldump]  
      53. quick  
      54. quote-names  
      55. max_allowed_packet = 32M    
      56.     
      57. [mysql]    
      58. no-auto-rehash    
  • 相关阅读:
    TCP与UDP
    DNS的概念,用途,DNS查询的实现算法
    子网划分的概念,子网掩码
    ping的原理以及ICMP
    组播和广播的概念,IGMP的用途
    ICMP协议
    RIP协议
    MTU的概念,什么是路径MTU? MTU发现机制,TraceRoute(了解)
    TFTP 与 FTP的区别
    vue slot slot-scope
  • 原文地址:https://www.cnblogs.com/jessieliang/p/6143206.html
Copyright © 2011-2022 走看看