zoukankan      html  css  js  c++  java
  • Ubuntu 12.04下安装MySQL图解

    先下载好mysql的linux安装包,从官网下,我下载的是5.6社区版, 下载后传到ubuntu上去。

    包放在~/download目录下,全部安装命令如下:

    1、解压tar.gz

    tar –xzf  mysql-5.6.26-linux-glibc2.5-x86_64.tar.gz

    2、重命名解压的文件夹

    mv mysql-5.6.26-linux-glibc2.5-x86_64 mysql

    3、将mysql文件夹移动到/usr/local目录下

    sudo mv ~/download/mysql  /usr/local

    4、进入mysql目录

    cd /usr/local/mysql

    5、增加mysql用户及组

    sudo useradd -r  mysql

    6、将mysql文件夹own及grp变更为mysql

    sudo chown -R mysql:mysql mysql/

    7、执行mysql安装脚本

    sudo scripts/mysql_install_db --user=mysql

    (若未安装libaio包,会有一个报错提示,安装libaio-dev后,再运行脚本即可。如果还是出错可以删除rm -rf /etc/my.cnf)

    sudo apt-get install libaio-dev

    8、将目录权限变更回来,仅保留data目录为mysql用户

    sudo chown -R root:root mysql .

    sudo chown -R mysql:mysql  data

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

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

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

    10、启动mysql

    sudo bin/mysqld_safe --user=mysql &

    11、初始化mysql root用户密码

    sudo bin/mysqladmin -u  root -p   '用户自定义密码';

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

    12、复制mysql.server脚本到/etc/init.d(初始化服务,有些人喜欢改成mysql,在这里改就可以)

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

    14、查看mysql运行状态

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

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

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

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

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

    16、将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

    17、允许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是因为我现在是一般用户(firehare),如果不加-u root的话,mysql会以为是firehare在登录。注意,我在这里没有进入根用户模式,因为没必要。一般来说,对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    

     

    参考文章: http://blog.csdn.net/njchenyi/article/details/17615391

  • 相关阅读:
    跟我学android—01.SplashActivity
    eclipse android : A project with that name already exists in the workspace
    冬吴相对论锦言佳句--0005.薄伽梵歌与“印度式管理”
    [转载]Jquery Form插件表单参数
    Form表单学习网站
    [转载]JQuery获取元素文档大小、偏移和位置和滚动条位置的方法集合
    jquery捕捉文本域输入事件
    [转载]js 遍历数组对象
    C#跳出循环的几种方法的区别
    [转载]MVC3缓存:使用页面缓存
  • 原文地址:https://www.cnblogs.com/jessieliang/p/6127850.html
Copyright © 2011-2022 走看看