{"id":902,"date":"2019-01-08T12:30:23","date_gmt":"2019-01-08T07:00:23","guid":{"rendered":"http:\/\/blog.openwebsolutions.in\/?p=902"},"modified":"2019-01-08T12:33:09","modified_gmt":"2019-01-08T07:03:09","slug":"use-mysql-ruby-rails-ubuntu","status":"publish","type":"post","link":"https:\/\/openwebsolutions.in\/blog\/use-mysql-ruby-rails-ubuntu\/","title":{"rendered":"How to use MySQL in Ruby on Rails  on Ubuntu?"},"content":{"rendered":"<p>&nbsp;<\/p>\n<p>Ruby on rails uses sqlite3 as a default database which is good for small application. If your project size is big, i.e. you need to handle large data throughout your project then\u00a0MySQL database is a better option.<\/p>\n<p>If your machine already has a MySQL, then there is no\u00a0need to install it again. In case, if MySQL is not present in your local machine, you can install it through the following procedure:<\/p>\n<p><strong>Command for installing MySQL:<\/strong><\/p>\n<ol>\n<li>update apt-get first in your machine<br \/>\nsudo apt-get update<\/li>\n<li>next install mysql and it libraries<br \/>\nsudo apt-get install mysql-server mysql-client libmysqlclient-dev*** Note: Durring installation, your local machine may ask the password for the root user<\/li>\n<li>next, you should run 2 more command below<br \/>\nsudo mysql_install_db<br \/>\nsudo mysql_secure_installation<\/li>\n<li>and finally, in your gemfile<br \/>\ngem install mysql2<\/li>\n<\/ol>\n<p><strong>If you have MySQL already, please skip the above 4 points.<\/strong><\/p>\n<p>Now, open the terminal and type<br \/>\n&gt; rails new app -d mysql<br \/>\nrails setup is created in your local machine<br \/>\n&gt; cd app<\/p>\n<p>open the database.yml<br \/>\n&gt; nano config\/database.yml<\/p>\n<p>You will see the below code in your editor<\/p>\n<div style=\"border: 2px solid #ccc; padding-left: 80px; padding-top: 25px; padding-bottom: 25px;\">\n<p># MySQL. Versions 5.1.10 and up are supported.<br \/>\n#<br \/>\n# Install the MySQL driver<br \/>\n# gem install mysql2<br \/>\n#<br \/>\n# Ensure the MySQL gem is defined in your Gemfile<br \/>\n# gem &#8216;mysql2&#8217;<br \/>\n#<br \/>\n# And be sure to use new-style password hashing:<br \/>\n# https:\/\/dev.mysql.com\/doc\/refman\/5.7\/en\/password-hashing.html<br \/>\n#<br \/>\ndefault: &amp;default<br \/>\nadapter: mysql2<br \/>\nencoding: utf8<br \/>\npool: &lt;%= ENV.fetch(&#8220;RAILS_MAX_THREADS&#8221;) { 5 } %&gt;<br \/>\nusername: PUT YOUR USERNAME<br \/>\npassword: PUT YOUR PASSWORD<br \/>\nsocket: \/var\/run\/mysqld\/mysqld.sockdevelopment:<br \/>\n&lt;&lt;: *default<br \/>\ndatabase: activeadmin_development# Warning: The database defined as &#8220;test&#8221; will be erased and<br \/>\n# re-generated from your development database when you run &#8220;rake&#8221;.<br \/>\n# Do not set this db to the same as development or production.<br \/>\ntest:<br \/>\n&lt;&lt;: *default<br \/>\ndatabase: activeadmin_test<\/p>\n<p># As with config\/secrets.yml, you never want to store sensitive information,<br \/>\n# like your database password, in your source code. If your source code is<br \/>\n# ever seen by anyone, they now have access to your database.<br \/>\n#<br \/>\n# Instead, provide the password as a unix environment variable when you boot<br \/>\n# the app. Read http:\/\/guides.rubyonrails.org\/configuring.html#configuring-a-database<br \/>\n# for a full rundown on how to provide these environment variables in a<br \/>\n# production deployment.<br \/>\n#<br \/>\n# On Heroku and other platform providers, you may have a full connection URL<br \/>\n# available as an environment variable. For example:<br \/>\n#<br \/>\n# DATABASE_URL=&#8221;mysql2:\/\/myuser:mypass@localhost\/somedatabase&#8221;<br \/>\n#<br \/>\n# You can use this database configuration with:<br \/>\n#<br \/>\n# production:<br \/>\n# url: &lt;%= ENV[&#8216;DATABASE_URL&#8217;] %&gt;<br \/>\n#<br \/>\nproduction:<br \/>\n&lt;&lt;: *default<br \/>\ndatabase: activeadmin_production<br \/>\nusername: activeadmin<br \/>\npassword: &lt;%= ENV[&#8216;ACTIVEADMIN_DATABASE_PASSWORD&#8217;] %&gt;<\/p>\n<\/div>\n<p>&nbsp;<\/p>\n<p>Change the username and password and save the database.yml file.<\/p>\n<p>Run<br \/>\n&gt; rake db:create<\/p>\n<p>Open your phpmyadmin, you can see the database which is newly created.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Ruby on rails uses sqlite3 as a default database which is good for small application. If your project size is big, i.e. you need to handle large data throughout your project then\u00a0MySQL database is a better option. If your machine already has a MySQL, then there is no\u00a0need to install it again. In case, [&hellip;]<\/p>\n","protected":false},"author":20,"featured_media":889,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[12,19,5],"tags":[41,63],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v14.8.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to use MySQL in Ruby on Rails on Ubuntu?<\/title>\n<meta name=\"description\" content=\"Ruby on rails uses sqlite3 as a default database which is good for small application. If your project size is big, i.e. you need to handle large data...\" \/>\n<meta name=\"robots\" content=\"index, follow\" \/>\n<meta name=\"googlebot\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<meta name=\"bingbot\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/openwebsolutions.in\/blog\/use-mysql-ruby-rails-ubuntu\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to use MySQL in Ruby on Rails on Ubuntu?\" \/>\n<meta property=\"og:description\" content=\"Ruby on rails uses sqlite3 as a default database which is good for small application. If your project size is big, i.e. you need to handle large data...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/openwebsolutions.in\/blog\/use-mysql-ruby-rails-ubuntu\/\" \/>\n<meta property=\"og:site_name\" content=\"Openweb Solutions Blog\" \/>\n<meta property=\"article:published_time\" content=\"2019-01-08T07:00:23+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-01-08T07:03:09+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/openwebsolutions.in\/blog\/wp-content\/uploads\/2019\/01\/blog1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1366\" \/>\n\t<meta property=\"og:image:height\" content=\"768\" \/>\n<meta name=\"twitter:card\" content=\"summary\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/openwebsolutions.in\/blog\/#website\",\"url\":\"https:\/\/openwebsolutions.in\/blog\/\",\"name\":\"Openweb Solutions Blog\",\"description\":\"Transforming ideas into reality\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"https:\/\/openwebsolutions.in\/blog\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/openwebsolutions.in\/blog\/use-mysql-ruby-rails-ubuntu\/#primaryimage\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/openwebsolutions.in\/blog\/wp-content\/uploads\/2019\/01\/blog1.png\",\"width\":1366,\"height\":768},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/openwebsolutions.in\/blog\/use-mysql-ruby-rails-ubuntu\/#webpage\",\"url\":\"https:\/\/openwebsolutions.in\/blog\/use-mysql-ruby-rails-ubuntu\/\",\"name\":\"How to use MySQL in Ruby on Rails on Ubuntu?\",\"isPartOf\":{\"@id\":\"https:\/\/openwebsolutions.in\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/openwebsolutions.in\/blog\/use-mysql-ruby-rails-ubuntu\/#primaryimage\"},\"datePublished\":\"2019-01-08T07:00:23+00:00\",\"dateModified\":\"2019-01-08T07:03:09+00:00\",\"author\":{\"@id\":\"https:\/\/openwebsolutions.in\/blog\/#\/schema\/person\/e27a52243ad3934ffa9590d2fd36ddd5\"},\"description\":\"Ruby on rails uses sqlite3 as a default database which is good for small application. If your project size is big, i.e. you need to handle large data...\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/openwebsolutions.in\/blog\/use-mysql-ruby-rails-ubuntu\/\"]}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/openwebsolutions.in\/blog\/#\/schema\/person\/e27a52243ad3934ffa9590d2fd36ddd5\",\"name\":\"Santanu Aich\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/openwebsolutions.in\/blog\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/b54e7427b9f8197e785e6f9c4668c23b?s=96&r=g\",\"caption\":\"Santanu Aich\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","_links":{"self":[{"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/posts\/902"}],"collection":[{"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/users\/20"}],"replies":[{"embeddable":true,"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/comments?post=902"}],"version-history":[{"count":5,"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/posts\/902\/revisions"}],"predecessor-version":[{"id":915,"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/posts\/902\/revisions\/915"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/media\/889"}],"wp:attachment":[{"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/media?parent=902"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/categories?post=902"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/tags?post=902"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}